Calculating the electric field of a dipole using an equation.

18 views (last 30 days)
Here is my code so far:
%This program will graph out the electric field lines between charges at
%(-1,0) and (1,0) with magnitudes of (q) and (-q)
%--------------------------------------------------------------------------
%Plots out the electric field lines between the charges
[X,Y]=meshgrid(-50:.2:50,-50:.2:50);
E=1.8.^(-1.5*sqrt(X.^2+Y.^2)).*cos(0.5*Y).*sin(X); %Electric field line equation
[DX,DY]=gradient(E,.2,.2);
quiver(X,Y,DX,DY)
hold on %Holds the previous set of code
%--------------------------------------------------------------------------
%Plots out equipotential surfaces of both charges
[X,Y]=meshgrid(-50:.1:50,-50:.1:50);
E=1.8.^(-1.5*sqrt(X.^2+Y.^2)).*cos(0.5*Y).*sin(X); %Equation for equipotential surfaces
contour(X,Y,E,10) %Where the magic of this wonder comes from baby
hold on %Holds the previous set of code
%--------------------------------------------------------------------------
%plots the points of both charges
x1=1; y1=0; %Negative charge location
x2=-1; y2=0; %Positive charge location
plot(x1,y1,'b:o') %plot of negative charge
plot(x2,y2,'r:o') %plot of positive charge
%--------------------------------------------------------------------------
%Gridlines, title and window view
grid on %Puts a gridline on the graph
axis([-2 2 -2 2]) %Sets the window to a 2X2 view
title('The plot of electric field lines and equipotential surfaces of q and (-q)')
The equation E=1.8.^(-1.5*sqrt(X.^2+Y.^2)).*cos(0.5*Y).*sin(X) I found in my matlab book "Matlab: an introduction with applications by Amos Gilat" while looking for a contour function, but I have no idea where the equation came from. If you run matlab with my code you come close to what I'm looking for as far as the electric field lines and equipotential surfaces. My guess is that the equation I am looking for will work for both electric field lines and equipotential surfaces.
My question is what equation do I use and how is it derived? Do I use E=kq/r^2 or something along the lines of V=kq/r? Thanks!

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!