Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
import numpy as np
import matplotlib.pyplot as plt
import math as Math

Q = 1 #Columb
E0 = 8.854187817e-12
K = 1/ (4 * Math.pi * E0)

gridx = np.arange(-5,5,0.1)
gridy = np.arange(-5,5,0.1)

x,y = np.meshgrid (gridx, gridy)

U = (K*Q * x) / (x**2 + y**2)^(3/2)
V = (K*Q * y) / (x**2 + y**2)^(3/2)

# eqn(x,y) = K*Q / (x**2 + y**2)^(1/2)
# grad = vector ( [ diff(eqn,x), diff(eqn,y) ] )
# Ex = diff (eqn, x)
# Ey = diff (eqn, y)

plt.figure (figsize = (10, 10))
#plt.streamplot (grad, x,y, color='green')
#plt.streamplot (x,y, Ex,Ey, color='green')
plt.streamplot (x,y, U,V, color='green')
plt.grid()
plt.show()

So, out of curiosity I attempted to convert the symbolic expression to a numpy array, and didn't find a conversion routine.

The other thing I did, was re-arrange the order of the equations and REM out the lines using the variable eqn. It appears that this one line converted the variables (x,y) to symbolic variables. I consider this to be a major failing of SageMath for not tattling, and for throwing other errors when the variables associated with eqn are passed to streamplot. I also consider it a major failing of streamplot that it can't use symbolic expressions.

So, the fix, is to not use symbolic equations with streamplot, at least and until streamplot updates their code to accommodate symbolic equations.