在 mpmath python 中计算的函数的实部和虚部分开

separate real and imaginary parts of a function evaluated in mpmath python

我在 mpmath 中计算一个 MeijerG 函数,结果是复数。我想分开实部和虚部以将它们保存在数据框中并随后绘制它们。我收到一个错误

TypeError: cannot create mpf from array followed by a series of complex numbers.

任何人都会有一个干净的方法来分离和保存这些数据,以便用户可以以任何格式绘制它们。

from mpmath import *
import sympy
import numpy as np
import cmath
import math
import pandas as pd
import matplotlib.pyplot as plt

mp.dps = 5; mp.pretty = True
a = mpf(0.25)
b = mpf(0.25)
z = mpc(0.75)
frequency = np.arange(1, 1e4, 100)

def q():
  return (-j/frequency)*meijerg([[1, 3/2], []], [[1, 1], [1/2, 0]], j*frequency)

T=q()
Re_q = np.real.T
Im_q = np.imag.T

print(Re_q)
print(Im_q)

data = pd.DataFrame({
    'Frequency (Hz)': frequency,
    'Re': Re_q,
    'Im': Im_q
}
)
data.to_csv('C:\Users\T.csv')

这样它就把实部和虚部分开了。

from mpmath import *
import numpy as np
import cmath
import math
import pandas as pd

mp.dps = 15; mp.pretty = True
a = mpf(0.25)
b = mpf(0.25)
z = mpf(0.75)
frequency = np.arange(1, 50, 10)  # frequeny range
bh = np.arange(10e-6, 30e-6, 10e-6) #10e-6 # width
print(bh)
D = 1e-6 #7.8e-4  # diffusivity
gamma = 0.5772 # Euler constant
v = []
w =[]
i = []
def q(frequency):
  for i in bh:
    # for f in frequency:
      omega = (((i ** 2) * 2 * math.pi * frequency) / D)  # depends on bh and frequency
      u = ((-j/(math.pi * omega))*meijerg([[1, 3/2], []], [[1, 1], [0.5, 0]], j*omega))
      v = np.real(u)
      w = np.imag(u)
      return i, frequency, v, w
#transpose arrays
T = np.vectorize(q)
print(T(frequency))
df = np.array(T(frequency)).T
print(df)
# create DataFrame
df1 = pd.DataFrame(data=df, columns=['bh', 'frequency','Re', 'Im'])
print(df1)
#save in .csv
df1.to_csv('C:\Users\Mohamed Boutchich\PycharmProjects\calculations\T.csv')