I'm trying to restrict a vector field plot to a specific region of the plane. I found the code for the plot_vector_field3d function online, and just modified that accordingly, but I'm having trouble with the 2d case. Here's what I have so far.
x,y = var('x y')
C = circle((0,0),1)
# useful functions
def norm2((x,y)):
"""
Norm squared of `(x,y)`
"""
return x^2 + y^2
def norm((x,y)):
"""
Norm of `(x,y)`
"""
return norm2((x,y)).sqrt()
def dy(x,y):
r = norm((x,y))
theta = arctan(y/x)
dr = cos(theta)*(1-1/r^2)
dtheta = -sin(theta)*(1+1/r^2)
if r<= 1:
return 0
else:
return dr*cos(theta)-r*sin(theta)*dtheta
def dx(x,y):
r = norm((x,y))
theta = arctan(y/x)
dr = cos(theta)*(1-1/r^2)
dtheta = -sin(theta)*(1+1/r^2)
if r<= 1:
return 0
else:
return dr*sin(theta) + r*cos(theta)*dtheta
VF = plot_vector_field((dx(x,y),dy(x,y)),(x,-2,2),(y,-2,2))
show(VF + C,aspect_ratio=1)
I'm not able to upload an image file, but if you run this, I'm trying to get rid of all of the vectors within the circle.