如何在simpy Python中找到复数向量字段的实部?

时间:2019-04-04 15:13:28

标签: python math simpy

我的向量字段太复杂了。我必须分离出复数矢量场的实部。如何在Python中使用 sympy 分离复杂矢量字段的实部? (与浆果连接和浆果曲率有关的矢量场)

我试图声明 k_x,k_y,k_z 为实数,并采用向量场的共轭,然后将向量及其共轭相加以获得向量的实部。但是当我宣布 k_x,k_y,k_z 为真实时,我遇到了一些错误。因此需要一些帮助将实部与向量分开。我在代码中得到的复杂字段是 B ,我必须将其实质分开。 (这是在 k k_x,k_y,k_z 的参考系中,它们在真实平面和中类似于 x,y,z > kx,ky,kz 是各个方向上的单位矢量)

import numpy as np 
from sympy import *
from sympy.physics.vector import *
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt



sigma_x = Matrix([[0,1],[1,0]]);
sigma_y = Matrix([[0,-1j],[1j,0]]);
sigma_z = Matrix([[1,0],[0,-1]]);

k=ReferenceFrame('k');

H=sigma_x*k[0]+sigma_y*k[1]+sigma_z*k[2];
H1=sigma_x*k[0]-sigma_y*k[1]+sigma_z*k[2];

t = H.eigenvects();
print(t);
psi_1=t[0][2];
psi_2=t[1][2];
psi_1=Matrix(psi_1);
psi_2=Matrix(psi_2);

t1 = H1.eigenvects();
psi_1h=t1[0][2];
psi_2h=t1[1][2];
psi_1h=Matrix(psi_1h).T;
psi_2h=Matrix(psi_2h).T;

grad_psi_1_0 = gradient(psi_1[0],k);
grad_psi_1_1 = gradient(psi_1[1],k);

A = (psi_1h[0]*grad_psi_1_0 + psi_1h[1]*grad_psi_1_1);
A=A*1j;


B=curl(A,k);

从代码中获得的结果B(复数向量字段)为:

  

(-1.0 * k_y k_z I *(-k_x + k_y I)(k_x + k_y I)(k_x 2 + k_y 2 +   k_z 2)(-1.5)/(k_z +(k_x 2 + k_y 2 + k_z 2)** 0.5)** 3 +   3.0 * k_y I (-k_x + k_y I)(-1.0 * k_z *(k_x 2   + k_y 2 + k_z 2)(-0.5)-1)*(k_x 2 + k_y 2 + k_z 2)( -0.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 4 + 1.0 *(-k_x   + k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5)-1)/( k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 3 + 1.0 * I *(k_x +   k_y I)(-1.0 * k_y k_z (k_x-k_y I)(k_x 2 + k_y 2 +   k_z 2)(-1.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2 +   1.0 * k_y *(k_x-k_y I)(-2.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5 )-2)*(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5)** 3 + I *(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(- 0.5)-   1)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2)/(k_z +(k_x 2 + k_y 2   + k_z 2) 0.5)+ 1.0 * I *(k_x + k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5)-1)*(1.0 * k_y *(k_x   -k_y I)(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2 + I /(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5))/(k_z +   (k_x 2 + k_y 2 + k_z 2) 0.5)** 2 + 1.0 *(k_x +   k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5)-1)/(k_z +   (k_x 2 + k_y 2 + k_z 2) 0.5)** 3)* kx +(1.0 * k_x k_z I *(-k_x +   k_y I)(k_x + k_y I)(k_x 2 + k_y 2 + k_z 2)(-1.5 )/(k_z +(k_x 2   + k_y 2 + k_z 2) 0.5)** 3-3.0 * k_x I (-k_x + k_y I)(k_x + k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5)-1)*( k_x 2 +   k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5) ** 4 +   1.0 * I *(-k_x + k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(- 0.5)-1)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 3-1.0 * I *(k_x +   k_y I)(-1.0 * k_x k_z (k_x-k_y I)(k_x 2 + k_y 2 +   k_z 2)(-1.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2 +   1.0 * k_x *(k_x-k_y I)(-2.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5 )-2)*(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5)** 3-(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5) --   1)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2)/(k_z +(k_x 2 + k_y 2   + k_z 2) 0.5)-1.0 * I *(k_x + k_y I)(-1.0 * k_z *(k_x 2 + k_y 2 + k_z 2)(-0.5)-1)*(1.0 * k_x *(k_x-k_y I)(k_x 2 + k_y 2 +   k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2-1-1 / (k_z +   (k_x 2 + k_y 2 + k_z 2) 0.5))/(k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5)** 2-1.0 * I *(k_x + k_y I)(-1.0 * k_z *(k_x 2 + k_y > 2 +   k_z 2)(-0.5)-1)/(k_z   +(k_x 2 + k_y 2 + k_z 2) 0.5)** 3)* ky +(1.0 * k_x I (k_x + k_y I)(1.0 * k_y *(k_x-k_y I)(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z   +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2 + I /(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5))*(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 +   k_y 2 + k_z 2) 0.5)** 2-1.0 * k_y I (k_x + k_y I)(1.0 * k_x *(k_x-   k_y I)(k_x 2 + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5)** 2-1-(/ k_z +(k_x 2 + k_y 2 + k_z 2) 0.5))*( k_x 2   + k_y 2 + k_z 2)(-0.5)/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5 )** 2-   1.0 *(1.0 * k_x *(k_x-k_y I)(k_x 2 + k_y 2 + k_z 2)(-0.5)/( k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2-1-(/ k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5))/(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)-   1.0 * I *(1.0 * k_y *(k_x-k_y I)(k_x 2 + k_y 2 + k_z 2)(-0.5) /(k_z +(k_x 2 + k_y 2 + k_z 2) 0.5)** 2 + I /(k_z +(k_x 2 + k_y 2 +   k_z 2) 0.5))/(k_z +(k_x 2 + k_y 2 + k_z 2)** 0.5))* k.z

我必须找到该向量的实部。

0 个答案:

没有答案