TypeError:abs()的错误操作数类型:“ ReferenceFrame”,但我没有abs()函数

时间:2019-04-21 20:14:21

标签: python curl vector typeerror sympy

我正在尝试使用其del运算符计算向量的卷曲,因此我使用了来自sympy的卷曲,并且仅使向量与参考框架交叉,但是我遇到了这个错误:我到底在做什么错误吗?

import sympy 
import numpy as np
import math 
from sympy import Symbol, diff, Array, sin, cos, curl
from sympy import init_printing
from sympy.physics.vector import curl, ReferenceFrame
init_printing()

# Variables being used - B0 is the initial mag field, alpha is a  constant. x/y/z are for the direction
alpha = Symbol('\u03B1')
B0 = Symbol('B0') 
x = Symbol('x')
y = Symbol('y')
z = Symbol('z')
print ('Symbols: ', alpha, B0, x, y, z)

# This has the reference frame and the vector
R = ReferenceFrame('R')
V = B0*sin(alpha*x)*R.y + B0*cos(alpha*x)*R.z
print(V)

C = curl(V,R)
print(C)

我希望/ nabla运算符穿过向量。

1 个答案:

答案 0 :(得分:0)

使用R[0]代替x。我从curl示例中推断出了这一点(并尝试复制一些Wiki示例)

isympy中运行

(无法从curl导入sympy

In [2]: from sympy.physics.vector import curl, ReferenceFrame  
   ...: alpha = Symbol('\u03B1')  
   ...: B0 = Symbol('B0')    
   ...: R = ReferenceFrame('R')  
   ...: V = B0*sin(alpha*R[0])*R.y + B0*cos(alpha*R[0])*R.z  
   ...: print(V)  
   ...: C = curl(V,R)  
   ...: print(C)  
   ...:  
   ...:                                                                              
B0*sin(R_x*α)*R.y + B0*cos(R_x*α)*R.z
B0*α*sin(R_x*α)*R.y + B0*α*cos(R_x*α)*R.z

可能有一种方法可以排除alpha,或者表明Calpha*V。我正在完成sympy教程。

In [4]: expand(C-alpha*V)                                                            
Out[4]: 0

In [8]: V                                                                            
Out[8]: B₀⋅sin(Rₓ⋅α) r_y + B₀⋅cos(Rₓ⋅α) r_z

In [9]: C                                                                            
Out[9]: B₀⋅α⋅sin(Rₓ⋅α) r_y + B₀⋅α⋅cos(Rₓ⋅α) r_z