Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
visualation of electric field line

Subject: visualation of electric field line

From: george veropoulos

Date: 17 Apr, 2012 09:37:05

Message: 1 of 2

Dear Friends
I m looking a matlab program or a matlab function
to produce the electric field line of various number electric
points charges...

Thank you in advance

George Veropoulos

Subject: visualation of electric field line

From: Bruno Luong

Date: 17 Apr, 2012 13:05:06

Message: 2 of 2

"george veropoulos" <veropgr@yahoo.gr> wrote in message <jmjdk1$s02$1@newscl01ah.mathworks.com>...
> Dear Friends
> I m looking a matlab program or a matlab function
> to produce the electric field line of various number electric
> points charges...
>

Easy enough. Here the charges are in a 2D plane:

n = 5; % number of charges
% locations
x=rand(n,1)-0.5;
y=rand(n,1)-0.5;
% charge
q = rand(n,1);
q = q - mean(q);

% Coulumb's number
ke = 8.9875517873681764e9;

xi = linspace(-1,1,33);
yi = linspace(-1,1,33);
[XI YI] = meshgrid(xi,yi);
zi = complex(XI,YI);
z = complex(x,y);

[ZI Z]=ndgrid(zi(:),z(:));

dZ = ZI-Z;
Zn = abs(dZ);

% http://en.wikipedia.org/wiki/Electric_field
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./E,Ey./E);
hold on
plot(x, y, 'or')
axis equal

% Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us