1 | initial version |
I think the problem is that you're trying to mix numpy
and matplotlib
and Sage in ways that are not supported. The documentation for plt.streamplot
says:
Parameters
**********
x, y : 1D/2D arrays
Evenly spaced strictly increasing arrays to make a grid. If 2D,
all rows of *x* must be equal and all columns of *y* must be equal;
i.e., they must be as if generated by "np.meshgrid(x_1d, y_1d)".
u, v : 2D arrays
*x* and *y*-velocities. The number of rows and columns must match
the length of *y* and *x*, respectively.
It looks like you're trying to pass grid
in the place of both x
and y
, but grid
is a function, not a pair of arrays of values. You also define x
and y
using np.meshgrid
, but the later assignment eqn(x,y) = K*Q / (x**2 + y**2)^(1/2)
redefines x
and y
to be symbolic variables. I suggest instead:
xx,yy = np.meshgrid (gridx, gridy) # don't redefine x and y
and
G = [grad(x,y) for (x,y) in zip(gridx,gridy)]
Gx = [a[0] for a in G]
Gy = [a[1] for a in G]
and finally
plt.streamplot (Gx, Gy, xx,yy, color='green')
This doesn't work, either, but the error message is different. Maybe you need to do more conversion to get xx
and Gx
in the same format (convert both to floats? convert Gx
to a numpy
array?).