I'm trying to find a solution to two functions. The functions are integrals involving four variables (eta, xi, a, c). The code first integrates with respect to eta, then xi, yielding a function only of a and c. It does this for two different sets of data, yielding two equations in two unknowns a and c. These need to be solved, however, I cannot seem to get the final line to work and got the following error message.
AttributeError: 'Tuple' object has no attribute 'as_coefficient'
Apologies if this code is poorly written -- I'm very new to this and would greatly appreciate any suggestions!
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))