Integral not calculating. Too many input requirements and error using function.

2 views (last 30 days)
Hi there. I am just trying to take the integral of a simple function in MATLAB and it is not calculating. I was messing with it for awhile and I went from too many input arguments to not enough input arguments. I am sure it is a simple solution, but I cannot seem to figure it out.
>> syms Z
>> E = @(Z) Z.^2.+9.
E =
function_handle with value:
@(Z)Z.^2. +9.
>> I = integral2(E, 0, 2, 0, 2*pi)
Error using @(Z)Z.^2. +9.
Too many input arguments.
Error in integral2Calc>integral2t/tensor (line
228)
Z = FUN(X,Y); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] =
integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q =
integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);

Accepted Answer

Basil C.
Basil C. on 12 Mar 2021
The error occurs from the fact you are performing a double integration but are passing only one variable so MATLAB doesnt know which limit applied to which variable. Rather try using this:
E = @(x,y) x.^2+9
or
E = @(x,y) y.^2+9
depending on your application and then perform the double integration
I = integral2(E, 0, 2, 0, 2*pi)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!