Ask Your Question
2

Visualize vector field with singularities

asked 2012-09-29 12:36:27 +0100

sagefan gravatar image

updated 2012-09-29 16:01:07 +0100

What's the best way to plot vector fields with singularities, for example if I take

var('x1 x2')
E1=vector([x1,x2])/(sqrt(x1^2+x2^2))^3
E2=E1.subs(x1=x1-1)
E=(E1-E2)
plot_vector_field(E,(x1,-3,3),(x2,-3,3))

I get the following ugly plot:

plot

Is it possible to exclude a region around the singularities?

There are some nice mathematica plots for a similar example in the answers to this question: http://mathematica.stackexchange.com/...

edit retag flag offensive close merge delete

Comments

1

There is certainly room for improvement in the `plot_vector_field` function. If someone implemented a way to customize the arrows based on the properties of the underlying vector you could easily color or filter out arrows who length was larger than a given upper bound which is what is done in one of the answers on the mathematica stack exchange.

benjaminfjones gravatar imagebenjaminfjones ( 2012-09-29 19:49:47 +0100 )edit

http://trac.sagemath.org/sage_trac/ticket/2922 would seem relevant.

kcrisman gravatar imagekcrisman ( 2012-09-29 22:03:39 +0100 )edit

Yeah, that would do the trick. I left a comment on the ticket, maybe it'll spur someone into wrapping that mpl function :)

benjaminfjones gravatar imagebenjaminfjones ( 2012-09-30 18:33:57 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-09-30 12:52:33 +0100

sagefan gravatar image

Just a first step:

var('x1 x2 v1 v2')

xmin = -2
xmax = 3
ymin = -2
ymax = 2

E1=vector([x1,x2])/(sqrt(x1^2+x2^2))^3
E2=E1.subs(x1=x1-1)
E= E1-E2

limit = 0.8
EE = (lambda x,y: norm(E(x,y)) < limit and E(x,y)[0] or 0,lambda x,y: norm(E(x,y)) < limit and E(x,y)[1] or 0)
vector_field = plot_vector_field(EE,(x1,xmin,xmax),(x2,ymin,ymax))
vector_field.show()

output

edit flag offensive delete link more

Comments

1

Yeah, massaging the data before plotting does work. It would be nice if this could be achieved in a simpler way that separates the styling and scaling of arrows from the data.

benjaminfjones gravatar imagebenjaminfjones ( 2012-09-30 18:37:18 +0100 )edit
1

answered 2012-09-29 15:32:55 +0100

achrzesz gravatar image
sage: maxima('E1:[x1,x2]/sqrt(x1^2+y^2)^3');         
sage: maxima('E2:subst(x1-1,x1,E1)');                
sage: maxima('E:E1-E2');                             
sage: maxima('plotdf(E,[x1,x2],[x1,-1,2],[x2,-1,1])')

Every click in the obtained vector field gives you a new trajectory

edit flag offensive delete link more

Comments

Here all arrows seem to have the same length.

sagefan gravatar imagesagefan ( 2012-09-29 16:00:27 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-09-29 12:36:27 +0100

Seen: 1,310 times

Last updated: Sep 30 '12