У меня есть скручивание магнитного поля, которое я рассчитал для построения графика, используя matplotlib, но в итоге получаю эту ошибку AttributeError. Я что-то не так делаю?
Я попытался изменить переменные от использования системы отсчета R [0] до просто x, но также включил векторы, используя систему отсчета декартовых координат.
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import axes3d
import sympy
from sympy import Symbol, diff, Array, sin, cos
from sympy import init_printing
from sympy.physics.vector import curl, ReferenceFrame
init_printing()
alpha = Symbol('\u03B1')
B0 = Symbol('B0')
R = ReferenceFrame('R')
# In order to get the curl, setting it as a vector
V = 0*R.x + B0*sin(alpha*R[0])*R.y + B0*cos(alpha*R[0])*R.z
# Calculates the curl of the vector, which results in a vector of
# alpha*B, which is correct
C = curl(V,R)
print('The curl of B is:',0*R.x + C,)
fig = plt.figure()
ax = fig.gca(projection = '3d')
x,y,z = np.meshgrid(np.arange(0.01, 1, 0.2),
np.arange(0.01, 1, 0.2),
np.arange(0.01, 1, 0.2))
u = 0*R.x
v = B0*alpha*sin(alpha*x)*R.y
w = B0*alpha*cos(alpha*x)*R.z
ax.quiver(x, y, z, u, v, w, length = 0.1)
plt.show()
Я ожидаю трехмерный график, показывающий векторное поле; ниже приведена трассировка ошибки.
AttributeError Traceback (most recent
call last)
<ipython-input-12-5974c739f1f4> in <module>
10 np.arange(0.01, 1, 0.2))
11 u = 0*R.x
---> 12 v = B0*alpha*sin(alpha*x)*R.y
13 w = B0*alpha*cos(alpha*x)*R.z
14
~/anaconda3/lib/python3.7/site-packages/sympy/core/function.py in
__new__(cls, *args, **options)
440
441 evaluate = options.get('evaluate',
global_evaluate[0])
--> 442 result = super(Function, cls).__new__(cls, *args,
**options)
443 if evaluate and isinstance(result, cls) and
result.args:
444 pr2 = min(cls._should_evalf(a) for a in
result.args)
~/anaconda3/lib/python3.7/site-packages/sympy/core/function.py in
__new__(cls, *args, **options)
249
250 if evaluate:
--> 251 evaluated = cls.eval(*args)
252 if evaluated is not None:
253 return evaluated
~/anaconda3/lib/python3.7/site-
packages/sympy/functions/elementary/trigonometric.py in eval(cls,
arg)
293 return arg._eval_func(cls)
294
--> 295 if arg.could_extract_minus_sign():
296 return -cls(-arg)
297
AttributeError: 'ImmutableDenseNDimArray' object has no attribute
'could_extract_minus_sign'