Processing math: 100%
Ask Your Question
0

How to plot field lines in sage

asked 12 years ago

sagefan gravatar image

updated 12 years ago

I want to plot the field lines of an electric field, take for example that of an electric dipole. How can I do this in sage?

Edit: Perhaps my question was formulated too much in physicist slang... Mathematically I just want to plot the integral curves of a vector field for example: let r(x,y)=(x,y), E1=r|r|3 and E2(x,y)=E1(x1,y)

Then I want to plot the field lines of E=E1E2

The field line plot should look similar to this one:

field line plot example

I think in mathematica this is called a stream plot: http://reference.wolfram.com/mathemat...

Preview: (hide)

5 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

calc314 gravatar image

updated 12 years ago

I don't think there's a way to automate this totally and avoid putting in all of the initial conditions. Here is another version.

var('x y')
E1=vector([x,3*y])/(sqrt(x^2+y^2))^(3/2)
E2=E1.subs(x=x-1)
F=(E1-E2)/norm(E1-E2)
int_conds=[[0.05,0.001],[0.05,0.005],[0.05,-0.001],[0.05,-0.005]]
solns=[desolve_odeint(F,init,srange(0,1.5,0.05),[x,y]) for init in int_conds]
nhalf=len(solns[0])/3
a=[arrow(solns[i][nhalf],solns[i][nhalf+1]) for i in range(0,len(solns))]
b=map(lambda x: line(x,thickness=2),solns)
show(sum(a)+sum(b)+point((0,0),size=50)+point((1,0),size=50)+plot_vector_field(F,(x,-0.1,1.1),(y,-.5,.5)),axes=false)

image description

Preview: (hide)
link
1

answered 12 years ago

calc314 gravatar image

updated 12 years ago

Thanks for the edit. See if something like this does what you want.

var('x y')
E1=vector([x,y])/(sqrt(x^2+y^2))^3
E2=E1.subs(x=x-1)
F=(E1-E2)

tstop=0.4
step=0.005
int_conds=[[0.5,0.1*k] for k in [1..3,-3..-1]]
solns=sum([line(desolve_odeint(F,init,srange(0,tstop,step),[x,y]),thickness=2) for init in int_conds])
solns2=sum([line(desolve_odeint(F,init,srange(0,-1*tstop,-1*step),[x,y]),thickness=2) for init in int_conds])

F=(E1-E2)/norm(E1-E2)
solns+solns2+plot_vector_field(F,(x,-0.2,1.2),(y,-1,1))
Preview: (hide)
link

Comments

Thanks, that's almost what I want. The missing point is that I want not only one or three lines but something like I added in the original post above.

sagefan gravatar imagesagefan ( 12 years ago )

Sorry I had two typos in my Edit, which I fixed just now, see above. You should not normalize F! Perhaps you could include those changes in your examples. Thanks.

sagefan gravatar imagesagefan ( 12 years ago )

I've updated my code a good bit to include your edits and some solving backwards and forwards from the initial condition.

calc314 gravatar imagecalc314 ( 12 years ago )
1

answered 12 years ago

achrzesz gravatar image

In the attached file one can see the maxima version (code in my previous answer)

sdfplot.pdf

Preview: (hide)
link
1

answered 12 years ago

calc314 gravatar image

updated 12 years ago

I'm not sure whether you already have equations to use or not. How you plot these all depends, of course, on how the equations are given. But, here is something. Using information in section D.73.3 of this webpage on quantum mechanics, we need to plot (x2+z2)(3/2)=cx2 for various values of c. The following code produces a plot.

var('x z')
sum([implicit_plot((x^2+z^2)^(3/2)==c*x^2,(x,-5,5),(z,-5,5)) for c in [1,2,3,4]])

image description

Preview: (hide)
link

Comments

That are the equipotential surfaces and not the field lines. You can assume that I know an analytic expression for the electric field strength at every point.

sagefan gravatar imagesagefan ( 12 years ago )

Can you post the expression?

calc314 gravatar imagecalc314 ( 12 years ago )

See my edit

sagefan gravatar imagesagefan ( 12 years ago )
1

answered 12 years ago

kcrisman gravatar image

People interested in this question will want to perhaps help out in making our ticket for streamline plots a reality.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 2,615 times

Last updated: Sep 30 '12