TypeError:abs()的错误操作数类型:"ReferenceFrame",但我没有abs()函数 [英] TypeError: Bad Operand Type for abs(): 'ReferenceFrame' but I have no abs() function

查看:53
本文介绍了TypeError:abs()的错误操作数类型:"ReferenceFrame",但我没有abs()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying calculate the curl of a vector with its del operator, and so I'm using the curl from sympy and just having the vector cross with the reference frame, but I get this error: what exactly am I doing wrong?

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运算符越过向量.

I'm expecting a /nabla operator cross the vector.

推荐答案

使用 R [0] 代替 x .我是从 curl 示例(并尝试复制一些Wiki示例)中推论得出的

Use R[0] instead of x. I deduced this from the curl examples (and trying to replicate some Wiki examples)

isympy

(无法从 sympy 导入 curl )

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 ,或者表明 C alpha * V .我正在完成 sympy 教程.

There may be a way of factoring out the alpha, or otherwise show that C is alpha*V. I'm just working through the sympy tutorials.

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

这篇关于TypeError:abs()的错误操作数类型:"ReferenceFrame",但我没有abs()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆