Error using + Matrix dimensions must agree. I want to find the value of Mt. Kindly help me clear the error.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
CODE:
a=0.1
s=0.01
N=5
wd=0.002906
d=5
for a1=a-((N-1)*(wd+s)):(wd+s):a
for b1=a-((N-1)*(wd+s)):(wd+s):a
r1=@(x,y) sqrt((x+a1).^2+(y+b1).^2+d.^2)
r2=@(x,y) sqrt((a1-x).^2+(y+b1).^2+d.^2)
r3=@(x,y) sqrt((a1-x).^2+(y-b1).^2+d.^2)
r4=@(x,y) sqrt((x+a1).^2+(y-b1).^2+d.^2)
C1=@(x) a1+x
C4=@(x) -a1-x
C2=@(x) a1-x
C3=@(x) -a1+x
d1=@(y) y+b1
d2=@(y) y+b1
d3=@(y) y-b1
d4=@(y) y-b1
fun=@(x,y) ((((u./(4.*pi)).*((((((-1).^1).*d1(y))./(r1(x,y).*(r1(x,y)+((-1).^(1.+1)).*C1(x))))-(C1(x)./(r1(x,y).*(r1(x,y)+d1(y)))))+(((((-1).^2).*d2(y))./(r2(x,y).*(r2(x,y)+(((-1).^(2.+1))).*C2(x))))-(C2(x)./(r2(x,y).*(r2(x,y)+d2(y)))))+(((((-1).^3).*d3(y))./(r3(x,y).*(r3(x,y)+(((-1).^(3.+1))).*C3(x))))-(C3(x)./(r3(x,y).*(r3(x,y)+d3(y)))))+(((((-1).^4).*d4(y))./(r4(x,y).*(r4(x,y)+((-1).^(4.+1)).*C4(x))))-(C4(x)./(r4(x,y).*(r4(x,y)+d4(y)))))))));
M = integral2(fun,-b1,b1,-b1,b1)
Mt=Mt+M
end
end
ERROR:
Error using +
Matrix dimensions must agree.
Error in @(x,y)sqrt((x+a1).^2+(y+b1).^2+d.^2)
Error in
@(x,y)((((u./(4.*pi)).*((((((-1).^1).*d1(y))./(r1(x,y).*(r1(x,y)+((-1).^(1.+1)).*C1(x))))-(C1(x)./(r1(x,y).*(r1(x,y)+d1(y)))))+(((((-1).^2).*d2(y))./(r2(x,y).*(r2(x,y)+(((-1).^(2.+1))).*C2(x))))-(C2(x)./(r2(x,y).*(r2(x,y)+d2(y)))))+(((((-1).^3).*d3(y))./(r3(x,y).*(r3(x,y)+(((-1).^(3.+1))).*C3(x))))-(C3(x)./(r3(x,y).*(r3(x,y)+d3(y)))))+(((((-1).^4).*d4(y))./(r4(x,y).*(r4(x,y)+((-1).^(4.+1)).*C4(x))))-(C4(x)./(r4(x,y).*(r4(x,y)+d4(y)))))))))
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);
Error in test (line 110)
M = integral2(fun,-b1,b1,-b1,b1)
5 comentarios
Rik
el 4 de Feb. de 2021
You can simulate what we will see by using clearvars before you run the code that you pasted here.
Respuestas (2)
Shiva Kalyan Diwakaruni
el 10 de Feb. de 2021
Hi,
You can try declaring and defining variables like u and Mt to see if the code is working . Error is occuring due to variable u and Mt not being defined.
thanks.
0 comentarios
VBBV
el 29 de Oct. de 2021
a=1.5; % make good guess
s=0.01;
N=5;
wd=0.002906;
d=5;
u=2; % guess
i = 1;
a1=a-((N-1)*(wd+s)):(wd+s):a;
b1=a-((N-1)*(wd+s)):(wd+s):a
for a1=a-((N-1)*(wd+s)):(wd+s):a
for b1=a-((N-1)*(wd+s)):(wd+s):a
r1=@(x,y) sqrt((x+a1).^2+(y+b1).^2+d.^2);
r2=@(x,y) sqrt((a1-x).^2+(y+b1).^2+d.^2);
r3=@(x,y) sqrt((a1-x).^2+(y-b1).^2+d.^2);
r4=@(x,y) sqrt((x+a1).^2+(y-b1).^2+d.^2);
C1=@(x) a1+x;
C4=@(x) -a1-x;
C2=@(x) a1-x;
C3=@(x) -a1+x;
d1=@(y) y+b1;
d2=@(y) y+b1;
d3=@(y) y-b1;
d4=@(y) y-b1;
fun=@(x,y) ((((u./(4.*pi)).*((((((-1).^1).*d1(y))./(r1(x,y).*(r1(x,y)+((-1).^(1+1)).*C1(x))))-(C1(x)./(r1(x,y).*(r1(x,y)+d1(y)))))+(((((-1).^2).*d2(y))./(r2(x,y).*(r2(x,y)+(((-1).^(2+1))).*C2(x))))-(C2(x)./(r2(x,y).*(r2(x,y)+d2(y)))))+(((((-1).^3).*d3(y))./(r3(x,y).*(r3(x,y)+(((-1).^(3+1))).*C3(x))))-(C3(x)./(r3(x,y).*(r3(x,y)+d3(y)))))+(((((-1).^4).*d4(y))./(r4(x,y).*(r4(x,y)+((-1).^(4+1)).*C4(x))))-(C4(x)./(r4(x,y).*(r4(x,y)+d4(y)))))))));
M(i)= integral2(fun,-b1,b1,-b1,b1); % integral value for each iteration
i=i+1;
end
end
M
Mt = sum(M)
plot(M);
0 comentarios
Ver también
Categorías
Más información sobre Mathematics and Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!