can some one explain the syntax of this code please
Afficher commentaires plus anciens
x=[3 8];
y=[5 5];
q=[-3 3];
% Coulumb's number
ke = 8.9875517873681764e9;
xi=linspace(0,10,20);
yi=linspace(0,10,20);
[XI YI] = meshgrid(xi,yi);
zi = complex(XI,YI);
z = complex(x,y);
[ZI Z]=ndgrid(zi(:),z(:));
dZ = ZI-Z;
Zn = abs(dZ);
E = (dZ./Zn.^3)*(q(:)*ke);
E = reshape(E,size(XI));
En = abs(E);
Ex = real(E);
Ey = imag(E);
figure;
quiver(XI,YI,Ex./En,Ey./En);
hold on;
plot(x,y,'Or');
axis equal;
Réponses (2)
Steven Lord
le 30 Déc 2022
1 vote
I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB. Once you've gone through that you should be able to understand much of that code. If you encounter a function with which you're not familiar read through its documentation page using the doc function.
7 commentaires
Moaz salah
le 30 Déc 2022
Image Analyst
le 30 Déc 2022
I suggest you take it one line at a time. First look up the function on the line in the help, and see what it does. Then make a comment before that line with a short description of what the following line does. Do that for every line in the program.
Moaz salah
le 30 Déc 2022
Image Analyst
le 30 Déc 2022
Modifié(e) : Image Analyst
le 30 Déc 2022
% Compute E from this mathematical formula.
E = (dZ./Zn.^3)*(q(:)*ke);
% reshape makes E the same size (rows and columns) as XI.
E = reshape(E,size(XI));
% abs takes the absolute value.
En = abs(E);
% real takes the real component of a complex number
Ex = real(E);
% imag takes the imaginary component of a complex number.
Ey = imag(E);
% figure brings up a new blank window.
figure;
% quiver plots a field of a bunch of little arrows.
quiver(XI,YI,Ex./En,Ey./En);
Moaz salah
le 30 Déc 2022
Walter Roberson
le 30 Déc 2022
Be careful there, the * operation is algebraic matrix multiplication (inner product) not element by element multiplication. Element by element is the .* operator
Moaz salah
le 30 Déc 2022
Image Analyst
le 30 Déc 2022
1 vote
To learn fundamental concepts, such as syntax, invest 2 hours of your time here:
Catégories
En savoir plus sur Vector Fields dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
