我试图找到两个功能的解决方案。函数是涉及四个变量(eta,xi,a,c)的积分。代码首先集成eta,然后是xi,只产生a和c的函数。它对两组不同的数据执行此操作,产生两个未知数a和c的两个方程。这些需要解决,但是,我似乎无法使最后一行工作并得到以下错误消息。
AttributeError: 'Tuple' object has no attribute 'as_coefficient'
如果这段代码写得不好,请道歉 - 我对此非常陌生,非常感谢任何建议!
from numpy import *
from scipy import *
from sympy import *
class dz_by_dxi:
def __init__(self, xi, a, c, lowlim_arg, uplim_arg, n_arg, lowlim_z,
uplim_z, n_z):
self.xi = xi
self.a = a
self.c = c
self.lowlim_arg = lowlim_arg
self.uplim_arg = uplim_arg
self.n_arg = n_arg
self.lowlim_z = lowlim_z
self.uplim_z = uplim_z
self.n_z = n_z
def __call__(self, eta_prime):
xi, a, c, lowlim_arg, uplim_arg, n_arg, lowlim_z, uplim_z, n_z = (
self.xi, self.a, self.c, self.lowlim_arg, self.uplim_arg, self.n_arg,
self.lowlim_z, self.uplim_z, self.n_z)
integrand_eta = ((eta_prime/(a**2 + eta_prime**2) + eta_prime/(c**2 +
eta_prime**2) - 2*eta_prime/(1 + eta_prime**2))*(pi -
2*atan(eta_prime/xi)))
integral_eta = Integral(integrand_eta, (eta_prime, lowlim_arg,
uplim_arg))
arg_dz = integral_eta.as_sum(n_arg, method = "midpoint")
dz = (abs(sqrt((xi+a)/(xi-a)))*abs(sqrt((xi+c)/(xi-c)))*
abs(((xi-1)/(xi+1)))*exp((1/pi)*arg_dz))
z = Integral(dz, (xi, lowlim_z, uplim_z))
return z.as_sum(n_z, method = "midpoint")
eta = Symbol('eta')
xi = Symbol('xi')
a = Symbol('a')
c = Symbol('c')
lowlim_arg = 0
uplim_arg = 100
n_arg = 2
lowlim_z = 0
uplim_z = 1
n_z = 2
ans_eqn_1 = 1.5
ans_eqn_2 = 0.5
instance_1 = dz_by_dxi(xi, a, c, lowlim_arg, uplim_arg, n_arg, lowlim_z, uplim_z, n_z)
instance_2 = dz_by_dxi(xi, a, c, lowlim_arg, uplim_arg, n_arg, lowlim_z, a, n_z)
eqn_1 = instance_1(eta) - ans_eqn_1
eqn_2 = instance_2(eta) - ans_eqn_2
solution = solve((eqn_1, eqn_2), (a, c), (0.4, 1.7))