hello, i am new on matlab and i keep getting this msg : matrix dimensions must agree!! any help please? its line 28

3 次查看(过去 30 天)
theta=linspace(0,2*pi);
phi=linspace(-pi/2,pi/2);
[theta,phi]=meshgrid(theta,phi);
krho=2;
[x,y,z]=sph2cart(theta,phi,krho);
surf(x,y,z);
kntot = 2^12; % kntot = nbr total des charges elem. 2^18=(2^9)^2=(2^6)^3
listn = linspace(1, kntot, kntot); % listn(ka,kb,knot) contient kntot elements
listn0 = listn - listn; % donc listn0 contient kntot elements tous 0
listn1 = sign(listn); % donc listn1 contient kntot elements tous 1
kconst= 9*(10^9); % kconst = 1/(4*pi*epsilon0)
kq= 10^(-6); % kq = charge totale = 1 uC (par exemple) dq= listn1*kq/kntot; % car charge uniforme (par exemple)
% dq = sign(sin(phi)).*listn1*kq/kntot;
kitot= 25; % kitot = nbr tot des points d'observation
kp1= -50; kp2= 50; % bornes de l'intervalle pour les points d'observation
kdp= (kp2-kp1)/kitot; % pas ou "step" pour les points d'observation
pt0= linspace(kp1+(kdp/2), kp2-(kdp/2), kitot); % pour les points d'observation
listi0=pt0-pt0; % donc listi0 contient kitot elements tous nuls
V=listi0;
% intialisation de liste du potentiel pour accelerer
Ex=listi0; Ey=listi0; Ez=listi0; % intialisations des composantes pour accelerer
kaltitude=10; kx0 = 0; ky0 = 0; kz0=kaltitude; % intialisation d'un point d'observation
for ki= 1 : kitot
kz0= pt0(ki); % car point d'observation sur l'axe z (par exemple)
dV= kconst*dq/( ( (kx0-x).^2+(ky0-y).^2+(kz0-z).^2 ).^0.5 );
V(ki)= sum(dV); % calcul de V pour le point d'observation numero ki
end;
figure; plot(pt0, V); title(' V(0,0,z) fonction de: z '); grid;

回答(1 个)

Sara
Sara 2014-12-23
Replace lines with this
dV = kconst*dq ./ ( ( (kx0-x).^2+(ky0-y).^2+(kz0-z).^2 ).^0.5 );
V(ki)= sum(sum(dV)); % calcul de V pour le point d'observation numero ki

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by