Need help in this error matrix integration
Show older comments
Hi, help, urgent, and I’m new. I am trying to do the following:
{E=10 nu=0.3 ebs=0 fun={@(x)1 @(x)x @(x)ebs ; @(x)x @(x)x^.2 @(x)x*ebs ; @(x)ebs @(x)x*ebs @(x)ebs.^2} A =cellfun(@(x)integral(x,-0.5,0.5),fun)}
And I get this error:
{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 132) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75) [q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct);
Error in matrix_integration>@(x)integral(x,-0.5,0.5)
Error in matrix_integration (line 19) A =cellfun(@(x)integral(x,-0.5,0.5),fun)
Can someone point what I am doing wrong?
Answers (1)
Steven Lord
on 9 Sep 2018
By default the integral function requires the integrand you pass into it as the first input argument to return an array the same size as the input. Several of the functions you've written do not satisfy that requirement. For example:
f = @(x)1
in = 1:10
out = f(in)
The variable in has 10 elements. The variable out has 1 element.
Use the 'ArrayValued' option in your integral call as the error message suggests.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!