How to plot of a double integral if error "Matrix dimensions must agree."
Afficher commentaires plus anciens
Hi to everybody, I didn't have any error for the first code but fir the second I obtain the error "matrix dimensions must agree". Howerver, I think the idea behind these 2 codes is the same... Why is there this error and how to solve it?
1) code without error
a=0.015;
b=0.01;
z = 0.006;
mu0 = 4*pi*10^-7;
x = linspace(0,0.016,8);
M = zeros(1,length(x));
for i=1:length(x)
f = @(theta,phi) a*b*cos(theta-phi)./sqrt((x(i)^2 + a^2 + b^2+ z^2 +2*b*x(i).*cos(phi) - 2*a*x(i).*cos(theta) - 2*a*b.*(cos(theta - phi)))) ;
M(i) = integral2(f,0,2*pi,0,2*pi);
end
figure;
plot(x,M);
2) code with error
r1=0.015;
r2=0.01;
z = 0.004;
mu0 = 4*pi*10^-7;
x = linspace(0,0.016,8);
M = zeros(1,length(x));
for i=1:length(x)
f = @(theta,phi) r1.*r2.*((1+theta.*phi).*cos(theta-phi)-(theta-phi).*sin(theta-phi))./sqrt(x.^2+(r1.*theta).^2+(r2.*phi).^2+z.^2+2.*r2.*x.*phi.*cos(phi)-2*r1.*x.*theta.*cos(theta)-2*r1.*r2.*theta.*phi.*cos(theta-phi));
M(i) = integral2(f,8.2*pi,10.2*pi,10.2*pi,15.2*pi);
end
figure;
plot(x,M);
error message :
Matrix dimensions must agree.
Error in
coil_2_archimede>@(theta,phi)r1.*r2.*((1+theta.*phi).*cos(theta-phi)-(theta-phi).*sin(theta-phi))./sqrt(x.^2+(r1.*theta).^2+(r2.*phi).^2+z.^2+2.*r2.*x.*phi.*cos(phi)-2*r1.*x.*theta.*cos(theta)-2*r1.*r2.*theta.*phi.*cos(theta-phi))
(line 9)
f = @(theta,phi)
r1.*r2.*((1+theta.*phi).*cos(theta-phi)-(theta-phi).*sin(theta-phi))./sqrt(x.^2+(r1.*theta).^2+(r2.*phi).^2+z.^2+2.*r2.*x.*phi.*cos(phi)-2*r1.*x.*theta.*cos(theta)-2*r1.*r2.*theta.*phi.*cos(theta-phi));
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 coil_2_archimede (line 10)
M(i) =
integral2(f,8.2*pi,10.2*pi,10.2*pi,15.2*pi);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Grid Lines, Tick Values, and Labels dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
