Integrating a constant in MATLAB

4 views (last 30 days)
Natalie
Natalie on 17 Nov 2013
Commented: Natalie on 17 Nov 2013
Hello,
I have a question about integrating a constant in MATLAB R=5 mess=@(T)R*T; integral(mess,20, 30) I get an answer. Or I do R=5 mess=@(T)R+T; integral(mess,20, 30), I also get the appropriate answer. But when I do R=5 mess=@(T)R; integral(mess,20, 30) The response I get is:
Error using integralCalc/finalInputChecks (line 515) Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315) finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 133) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76) [q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 89) Q = integralCalc(fun,a,b,opstruct);
Error in Untitled8 (line 6) integral(mess,20, 30)
It seems that it has something to do with the fact that I'm integrating a constant that is not affected by T? Is there a way to calculate the integral without having write out the integral as R(T2-T1)?

Accepted Answer

Walter Roberson
Walter Roberson on 17 Nov 2013
mess = @(T) R * ones(size(T));

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 17 Nov 2013
R=5
mess=@(T)R;
integral(mess,20, 30, 'ArrayValued',true)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!