I am getting an error 'Integrand output size does not match the input size' while using integral2

6 views (last 30 days)
Hi,
I am numerically evaluating the double integral using integral2 matlab command. My code is as follows :
l1=0; m1=0; l2=0; m2=0;
funn = @(theta,phi)((Y_hsph_new(1,l1,m1,theta,phi))*(Y_sph_new(1,l2,m2,theta,phi)));
q = integral2(funn,0,pi/2,0,2*pi);
where 'Y_hsph_new' and 'Y_sph_new' are my own designed matlab function, whose output is a scalar value. While running this small code, I am geeting error :-
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
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);
Error in Coeff_conversion (line 21)
q = integral2(funn,0,pi/2,0,2*pi);
I tried to solve this but I am not understnding what's wrong in it. Can anyone help me in this regard. Thank You

Accepted Answer

Amita Giri
Amita Giri on 23 Jun 2020
I solved the above mentioned problem and thought to share with you all.
The problem is with the way funn is defined. As I metioned Y_hsph_new and Y_sph_new give a scalar value as an output. . Whereas, the input theta and phi is a 2D matrix (which I mistaken to be also a scalar value). I re-coded the Y_hsph and Y_sph_new in such a way that it takes 2D theta, phi, and generate output as of same dimension. Also, * (multiplication) is replaced by .* (point-wise multiplication) which is as follows :
funn = @(theta,phi)((Y_hsph_new(1,l1,m1,theta,phi)).*(Y_sph_new(1,l2,m2,theta,phi)));
If anyone has any more question feel free to ask. cheers!!!

More Answers (0)

Categories

Find more on Programming 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!