Integrand output size does not match the input size. Kindly help me clear the error.

3 views (last 30 days)
Swathi S
Swathi S on 10 Sep 2019
Commented: Walter Roberson on 11 Sep 2019
CODE:
%all variables are declared
for ai=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
for aj=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
Bz= @(x,y) (((u./(4.*pi)).*((((((-1).^1).*d1(ai))./(r1(ai).*(r1(ai)+((-1).^(1+1)).*C1(ai))))-(C1(ai)./(r1(ai).*(r1(ai)+d1(ai)))))+(((((-1).^2).*d2(ai))./(r2(ai).*(r2(ai)+(((-1).^(2+1))).*C2(ai))))-(C2(ai)./(r2(ai).*(r2(ai)+d2(ai)))))+(((((-1).^3).*d3(ai))./(r3(ai).*(r3(ai)+(((-1).^(3+1))).*C3(ai))))-(C3(ai)./(r3(ai).*(r3(ai)+d3(ai)))))+(((((-1).^4).*d4(ai))./(r4(ai).*(r4(ai)+((-1).^(4+1)).*C4(ai))))-(C4(ai)./(r4(ai).*(r4(ai)+d4(ai))))))))
M=integral2(Bz,-aj,aj,-aj,aj)
Mtl=Mtl+M
Mtotal=(Mtl./2).*J.*G
hold on
end
end
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 FPSSCFINAL10Sep192 (line 108)
M=integral2(Bz,-aj,aj,-aj,aj)
  1 Comment
Walter Roberson
Walter Roberson on 11 Sep 2019
You have
Bz= @(x,y) (((u./(4.*pi)).*((((((-1).^1).*d1(ai))./(r1(ai).*(r1(ai)+((-1).^(1+1)).*C1(ai))))-(C1(ai)./(r1(ai).*(r1(ai)+d1(ai)))))+(((((-1).^2).*d2(ai))./(r2(ai).*(r2(ai)+(((-1).^(2+1))).*C2(ai))))-(C2(ai)./(r2(ai).*(r2(ai)+d2(ai)))))+(((((-1).^3).*d3(ai))./(r3(ai).*(r3(ai)+(((-1).^(3+1))).*C3(ai))))-(C3(ai)./(r3(ai).*(r3(ai)+d3(ai)))))+(((((-1).^4).*d4(ai))./(r4(ai).*(r4(ai)+((-1).^(4+1)).*C4(ai))))-(C4(ai)./(r4(ai).*(r4(ai)+d4(ai))))))))
The calculations on the right hand side do not use x or y, so whatever it returns is not going to be the same size as x and y
The function you pass into integral2() is not passed scalar x and y: it is passed arrays of x and y that are the same size, and it is responsible for returning a result that is the same size as x.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!