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

조회 수: 2 (최근 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