Can you please tell me, I need to symbolically solve a system of linear equations using sympy in python. I have programmed the automatic creation of a system of linear equations, the number of equations is determined by the number n (predefined). I set the variables too.
it turns out the following:
########## system of linear equations ##########
[-mui0*exp(Ea0**2/(T0*k)) - mui0*exp(Ea1**2/(T0*k)) - mui0*exp(Ea2**2/(T0*k)) - mui0*exp(Ea3**2/(T0*k)) + (Eb0**2/(T0*k) - 2*Ec0)*exp(Ea0**2/(T0*k)) + (Eb1**2/(T0*k) - 2*Ec1)*exp(Ea1**2/(T0*k)) + (Eb2**2/(T0*k) - 2*Ec2)*exp(Ea2**2/(T0*k)) + (Eb3**2/(T0*k) - 2*Ec3)*exp(Ea3**2/(T0*k)), -mui1*exp(Ea0**2/(T1*k)) - mui1*exp(Ea1**2/(T1*k)) - mui1*exp(Ea2**2/(T1*k)) - mui1*exp(Ea3**2/(T1*k)) + (Eb0**2/(T1*k) - 2*Ec0)*exp(Ea0**2/(T1*k)) + (Eb1**2/(T1*k) - 2*Ec1)*exp(Ea1**2/(T1*k)) + (Eb2**2/(T1*k) - 2*Ec2)*exp(Ea2**2/(T1*k)) + (Eb3**2/(T1*k) - 2*Ec3)*exp(Ea3**2/(T1*k)), -mui2*exp(Ea0**2/(T2*k)) - mui2*exp(Ea1**2/(T2*k)) - mui2*exp(Ea2**2/(T2*k)) - mui2*exp(Ea3**2/(T2*k)) + (Eb0**2/(T2*k) - 2*Ec0)*exp(Ea0**2/(T2*k)) + (Eb1**2/(T2*k) - 2*Ec1)*exp(Ea1**2/(T2*k)) + (Eb2**2/(T2*k) - 2*Ec2)*exp(Ea2**2/(T2*k)) + (Eb3**2/(T2*k) - 2*Ec3)*exp(Ea3**2/(T2*k)), -mui3*exp(Ea0**2/(T3*k)) - mui3*exp(Ea1**2/(T3*k)) - mui3*exp(Ea2**2/(T3*k)) - mui3*exp(Ea3**2/(T3*k)) + (Eb0**2/(T3*k) - 2*Ec0)*exp(Ea0**2/(T3*k)) + (Eb1**2/(T3*k) - 2*Ec1)*exp(Ea1**2/(T3*k)) + (Eb2**2/(T3*k) - 2*Ec2)*exp(Ea2**2/(T3*k)) + (Eb3**2/(T3*k) - 2*Ec3)*exp(Ea3**2/(T3*k))]
###### vars ######
[Ea0, Ea1, Ea2, Ea3, Ea4, Eb0, Eb1, Eb2, Eb3, Eb4, Ec0, Ec1, Ec2, Ec3, Ec4]
###### ###### ###### ###### ###### ###### ###### ######
now when i write : a = linsolve(list_eq,list_var)
the error gets out : SympifyError: Sympify of expression 'could not parse '['' failed, because of exception being raised:
TokenError: ('EOF in multi-line statement', (2, 0))
how to be For sympy to find a solution to a system of linear equations
this is my full code :
from sympy import exp,symbols
from sympy import Float,linsolve
def chis_znam_construct(T,i_eq,n):
En1 = symbols('Eb:' + str(n+1))
En0 = symbols('Ea:' + str(n+1))
En2 = symbols('Ec:' + str(n+1))
mui = symbols('mui:' + str(n+1))
k = symbols('k')
chis=0
znam=0
i_levels=0
eq=[]
varS=[]
dictvanfleck=dict({})
dictvanfleck['eq']=[]
dictvanfleck['vars']=[]
def getvars(f,varS):
i_var=0
while i_var<=(len(f)-1):
varS.append(f[i_var])
i_var+=1
return varS
variable=getvars(En0,varS)
variable=getvars(En1,varS)
variable=getvars(En2,varS)
for i_levels in range(n):
chis+=((En1[i_levels]**2)/(k*T)-
(En2[i_levels]+En2[i_levels]))*exp((En0[i_levels]**2)/(k*T))
znam+=mui[i_eq]*exp((En0[i_levels]**2)/(k*T))
i_levels+=1
print('')
print('')
eq.append(chis-znam)
dictvanfleck['vars']=variable
dictvanfleck['eq']=eq
return dictvanfleck
def eq_construct(T,n):
i_eq=0
eq=[]
for i_eq in range(n):
eq.append(chis_znam_construct(T[i_eq],i_eq,n))
i_eq+=1
return eq
print('')
print('')
def solve_eq(T,n):
equations=eq_construct(T,n)
eqA=equations[1]
var=eqA['vars']
i=0
equat=[]
while i<=(n-1):
eqA=equations[i]
eqq=eqA['eq']
equat.append(eqq[0])
i+=1
list_eq=str(equat)
list_var=str(var)
print('')
print('list_eq',list_eq)
print('')
print('list_var',list_var)
a = linsolve(list_eq,list_var)
return a
n = 4
T = symbols('T:' + str(n+1))
equations=solve_eq(T,n)
you will laugh, but an error was found: firstly, I made a tuple from list, some of the errors were gone; but the most interesting thing is that when I explicitly set equations and variables, simpi cannot solve the equations :
n = 4
T = sp.symbols('T:' + str(n+1))
Ea0, Ea1, Ea2, Ea3, Ea4, Eb0, Eb1, Eb2, Eb3, Eb4, Ec0, Ec1, Ec2, Ec3, Ec4, T0, T1, T2,
T3, T4, mui0, mui1, mui2, mui3, mui4 = sp.symbols('Ea0, Ea1, Ea2, Ea3, Ea4, Eb0, Eb1,
Eb2, Eb3, Eb4, Ec0, Ec1, Ec2, Ec3, Ec4, T0, T1, T2, T3, T4, mui0, mui1, mui2, mui3,
mui4')
eq_one=sp.Eq(-mui0*exp(Ea0**2/(T0*k)) - mui0*exp(Ea1**2/(T0*k)) -
mui0*exp(Ea2**2/(T0*k)) -
mui0*exp(Ea3**2/(T0*k)) + (Eb0**2/(T0*k) - 2*Ec0)*exp(Ea0**2/(T0*k)) +
(Eb1**2/(T0*k) - 2*Ec1)*exp(Ea1**2/(T0*k)) + (Eb2**2/(T0*k) -
2*Ec2)*exp(Ea2**2/(T0*k)) +
(Eb3**2/(T0*k) - 2*Ec3)*exp(Ea3**2/(T0*k)))
eq_two=sp.Eq(-mui1*exp(Ea0**2/(T1*k)) - mui1*exp(Ea1**2/(T1*k)) -
mui1*exp(Ea2**2/(T1*k)) - mui1*exp(Ea3**2/(T1*k)) +
(Eb0**2/(T1*k) - 2*Ec0)*exp(Ea0**2/(T1*k)) + (Eb1**2/(T1*k) -
2*Ec1)*exp(Ea1**2/(T1*k)) + (Eb2**2/(T1*k) - 2*Ec2)*exp(Ea2**2/(T1*k)) +
(Eb3**2/(T1*k) - 2*Ec3)*exp(Ea3**2/(T1*k)))
eq_three=sp.Eq(-mui2*exp(Ea0**2/(T2*k)) - mui2*exp(Ea1**2/(T2*k)) -
mui2*exp(Ea2**2/(T2*k)) -
mui2*exp(Ea3**2/(T2*k)) + (Eb0**2/(T2*k) - 2*Ec0)*exp(Ea0**2/(T2*k)) +
(Eb1**2/(T2*k) - 2*Ec1)*exp(Ea1**2/(T2*k)) + (Eb2**2/(T2*k) -
2*Ec2)*exp(Ea2**2/(T2*k)) +
(Eb3**2/(T2*k) - 2*Ec3)*exp(Ea3**2/(T2*k)))
eq_four=sp.Eq(-mui3*exp(Ea0**2/(T3*k)) - mui3*exp(Ea1**2/(T3*k)) -
mui3*exp(Ea2**2/(T3*k)) - mui3*exp(Ea3**2/(T3*k)) + (Eb0**2/(T3*k) -
2*Ec0)*exp(Ea0**2/(T3*k)) +
(Eb1**2/(T3*k) - 2*Ec1)*exp(Ea1**2/(T3*k)) + (Eb2**2/(T3*k) -
2*Ec2)*exp(Ea2**2/(T3*k)) +
(Eb3**2/(T3*k) - 2*Ec3)*exp(Ea3**2/(T3*k)))
ans = sp.solve((eq_one, eq_two,eq_three,eq_four), (Ea0, Ea1, Ea2, Ea3))
print('ответ :', ans)
raise NotImplementedError('could not solve %s' % eq2)
NotImplementedError: could not solve ....
Related
import pyomo.environ as pyo
import numpy as np
def get_model_garch11mle(vec_retn: np.array) -> pyo.ConcreteModel:
mdl = pyo.ConcreteModel(name='GARCH11')
mdl.alpha_0 = pyo.Var(bounds=(1e-6,1), initialize=.4)
mdl.alpha_1 = pyo.Var(bounds=(1e-6,1), initialize=.4)
mdl.beta_1 = pyo.Var(bounds=(1e-6,1), initialize=.4)
mdl.T = range(len(vec_retn))
mdl.h_t = pyo.Expression(mdl.T)
for i in mdl.T:
if i == 0:
mdl.h_t[i] = pyo.Expression(expr=mdl.alpha_0 / (1 - mdl.alpha_1 - mdl.beta_1))
else:
mdl.h_t[i] = pyo.Expression(expr=mdl.alpha_0 + mdl.alpha_1 * (vec_retn[i - 1]**2) + mdl.beta_1 * mdl.h_t[i - 1])
mdl.obj = pyo.Objective(expr=sum([pyo.log(mdl.h_t[i]) + vec_retn[i]**2/mdl.h_t[i] for i in mdl.T]))
return mdl
vec_retn = np.random.randn(100)**2 /3 + np.random.randn(100)**3 /6
temp_mdl = get_model_garch11mle(vec_retn)
opt = pyo.SolverFactory('gurobi')
temp_res = opt.solve(temp_mdl)
In this snippet I need to update a seq of h[t] using variables (a0, a1, b1) and h[t-1]. Curious what's the proper way to write the problem for Pyomo?
Currently, I got:
ValueError: Accessing the expression of expression 'ScalarExpression'
before the Expression has been constructed (there is currently no value to return).
When removed redundant 'Expression()' as:
import pyomo.environ as pyo
import numpy as np
def get_model_garch11mle(vec_retn: np.array) -> pyo.ConcreteModel:
mdl = pyo.ConcreteModel(name='GARCH11')
mdl.alpha_0 = pyo.Var(bounds=(1e-6, 1), initialize=.4)
mdl.alpha_1 = pyo.Var(bounds=(1e-6, 1), initialize=.4)
mdl.beta_1 = pyo.Var(bounds=(1e-6, 1), initialize=.4)
mdl.T = range(len(vec_retn))
mdl.h_t = pyo.Expression(mdl.T)
for i in mdl.T:
if i == 0:
mdl.h_t[i] = mdl.alpha_0 / (1 - mdl.alpha_1 - mdl.beta_1)
else:
mdl.h_t[i] = mdl.alpha_0 + mdl.alpha_1 * vec_retn[
i - 1]**2 + mdl.beta_1 * mdl.h_t[i - 1]
mdl.obj = pyo.Objective(expr=sum(
pyo.log(mdl.h_t[i]) + vec_retn[i]**2 / mdl.h_t[i] for i in mdl.T))
return mdl
vec_retn = np.random.randn(100)**2 / 3 + np.random.randn(100)**3 / 6
temp_mdl = get_model_garch11mle(vec_retn)
opt = pyo.SolverFactory('mosek')
temp_res = opt.solve(temp_mdl)
when using 'mosek':
DegreeError: MOSEK does not support expressions of degree None.
when using 'gurobi':
RuntimeError: Cannot write legal LP file. Objective 'obj' has nonlinear terms that are not quadratic.
The problem is in your for-loop, you don't need to declare new Expression components just assign the expression to the appropriate index:
for i in mdl.T:
if i == 0:
mdl.h_t[i] = mdl.alpha_0 / (1 - mdl.alpha_1 - mdl.beta_1)
else:
mdl.h_t[i] = mdl.alpha_0 + mdl.alpha_1 * (vec_retn[i - 1]**2) + mdl.beta_1 * mdl.h_t[i - 1]
I have a system of 28 nonlinear equations with 27 dependent variables.
x0 = np.ones(27)
def one_VI_set_012(x):
gamma1 = x[0] + 1j*x[1]
Zw1 = x[2] + 1j*x[3]
gamma0 = x[4] + 1j*x[5]
Zw0 = x[6] + 1j*x[7]
len1 = x[8]
len2 = len - x[8]
I_left_f1 = x[9] * np.exp(1j*x[10]*np.pi/180)
I_right_f1 = x[11] * np.exp(1j * x[12]*np.pi/180)
V_f1 = x[13] * np.exp(1j * x[14]*np.pi/180)
I_left_f2 = x[15] * np.exp(1j*x[16]*np.pi/180)
I_right_f2 = x[17] * np.exp(1j * x[18]*np.pi/180)
V_f2 = x[19] * np.exp(1j * x[20]*np.pi/180)
I_left_f0 = x[21] * np.exp(1j*x[22]*np.pi/180)
I_right_f0 = x[23] * np.exp(1j * x[24]*np.pi/180)
V_f0 = x[25] * np.exp(1j * x[26]*np.pi/180)
return [ \
np.real(V_f1 - (Vbeg_1*np.cosh(gamma1*len1) - Ibeg_1*Zw1*np.sinh(gamma1*len1))),
np.real(I_left_f1 - (-Vbeg_1*np.sinh(gamma1*len1)/Zw1 + Ibeg_1*np.cosh(gamma1*len1))),
np.real(Vend_1 - (V_f1*np.cosh(gamma1*len2) - I_right_f1*Zw1*np.sinh(gamma1*len2))),
np.real(Iend_1 - (-V_f1*np.sinh(gamma1*len2)/Zw1 + I_right_f1*np.cosh(gamma1*len2))),
np.real(V_f2 - (Vbeg_2*np.cosh(gamma1*len1) - Ibeg_2*Zw1*np.sinh(gamma1*len1))),
np.real(I_left_f2 - (-Vbeg_2*np.sinh(gamma1*len1)/Zw1 + Ibeg_2*np.cosh(gamma1*len1))),
np.real(Vend_2 - (V_f2*np.cosh(gamma1*len2) - I_right_f2*Zw1*np.sinh(gamma1*len2))),
np.real(Iend_2 - (-V_f2*np.sinh(gamma1*len2)/Zw1 + I_right_f2*np.cosh(gamma1*len2))),
np.real(V_f0 - (Vbeg_0*np.cosh(gamma0*len1) - Ibeg_0*Zw0*np.sinh(gamma0*len1))),
np.real(I_left_f0 - (-Vbeg_0*np.sinh(gamma0*len1)/Zw0 + Ibeg_0*np.cosh(gamma0*len1))),
np.real(Vend_0 - (V_f0*np.cosh(gamma0*len2) - I_right_f0*Zw0*np.sinh(gamma0*len2))),
np.real(Iend_0 - (-V_f0*np.sinh(gamma0*len2)/Zw0 + I_right_f0*np.cosh(gamma0*len2))),
np.real((I_left_f1 - I_right_f1) - (I_left_f0 - I_right_f0)),
np.real((I_left_f1 - I_right_f1) - (I_left_f2 - I_right_f2)),
np.imag(V_f1 - (Vbeg_1*np.cosh(gamma1*len1) - Ibeg_1*Zw1*np.sinh(gamma1*len1))),
np.imag(I_left_f1 - (-Vbeg_1*np.sinh(gamma1*len1)/Zw1 + Ibeg_1*np.cosh(gamma1*len1))),
np.imag(Vend_1 - (V_f1*np.cosh(gamma1*len2) - I_right_f1*Zw1*np.sinh(gamma1*len2))),
np.imag(Iend_1 - (-V_f1*np.sinh(gamma1*len2)/Zw1 + I_right_f1*np.cosh(gamma1*len2))),
np.imag(V_f2 - (Vbeg_2*np.cosh(gamma1*len1) - Ibeg_2*Zw1*np.sinh(gamma1*len1))),
np.imag(I_left_f2 - (-Vbeg_2*np.sinh(gamma1*len1)/Zw1 + Ibeg_2*np.cosh(gamma1*len1))),
np.imag(Vend_2 - (V_f2*np.cosh(gamma1*len2) - I_right_f2*Zw1*np.sinh(gamma1*len2))),
np.imag(Iend_2 - (-V_f2*np.sinh(gamma1*len2)/Zw1 + I_right_f2*np.cosh(gamma1*len2))),
np.imag(V_f0 - (Vbeg_0*np.cosh(gamma0*len1) - Ibeg_0*Zw0*np.sinh(gamma0*len1))),
np.imag(I_left_f0 - (-Vbeg_0*np.sinh(gamma0*len1)/Zw0 + Ibeg_0*np.cosh(gamma0*len1))),
np.imag(Vend_0 - (V_f0*np.cosh(gamma0*len2) - I_right_f0*Zw0*np.sinh(gamma0*len2))),
np.imag(Iend_0 - (-V_f0*np.sinh(gamma0*len2)/Zw0 + I_right_f0*np.cosh(gamma0*len2))),
np.imag((I_left_f1 - I_right_f1) - (I_left_f0 - I_right_f0)),
np.imag((I_left_f1 - I_right_f1) - (I_left_f2 - I_right_f2))]
root = least_squares(one_VI_set_012,x0)
Vbeg_1, Ibeg_1 etc. here are the complex numbers which are given in the rest of the code. I've tried to perform regression on a simple system of 3 equations and all was good, but in real abovemetioned task I receive an error:
Exception has occurred: TypeError
ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Thank you very much in advance.
I'm trying to solve a long block of equations from an EES implementation using the scipy.optimze.fsolve. But in this block of equations there are CoolProp calls that have a range of validation, and sometimes it yields ValueError. I want to know if there is a strategy to avoid ValueError and let fsolve try another guesses.
This is my code:
def block1(x):
def cp_gas(Ti, Tj):
return (1000/(Tj - Ti)*(x[6]*1.25 + x[1]*(0.45 *(((Tj + 273.15)/1000)
-((Ti + 273.15)/1000)) + 1.67*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
- 1.27*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
+ 0.39*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[2]*(1.79 *(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
+ 0.107*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.586*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.2*(((Tj + 273.15)/1000)**4 -((Ti + 273.15)/1000)**4)/4)
+ x[3]*(1.11*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
- 0.48*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.96*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.42*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[4]*(0.88*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
- 0.0001*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.54*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.33*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[5]*(0.37*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
+ 1.05*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
- 0.77*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
+ 0.21*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)))
f = np.zeros(26)
# x[24] = T_out_vent
f[0] = x[0] - cp_gas(T0, Tgas5)
f[1] = m_gas_teoria_conferindo*x[8] - x[9]*0.8 - x[7]
f[2] = x[10] + x[8] - (x[7] + x[9]*0.8)
f[3] = x[9] - x[8]*Z
f[4] = x[12] + x[13] + x[14] + x[15] + x[16] + x[17] - x[11]
f[5] = x[12] - M_CO2*x[8]/x[7]
f[6] = x[13] - M_H2O*x[8]/x[7]
f[7] = x[14] - M_N2*x[8]/x[7]
f[8] = x[15] - M_O2*x[8]/x[7]
f[9] = x[16] - M_SO2*x[8]/x[7]
f[10] = x[17] - (M_Cz*x[8] - 0.8*x[9])/x[7]
f[11] = x[18] - (e*a*((1-omega_ar) + 3.76*(1-omega_ar) + omega_ar)*(MM_ar_CBG)/(MM_CBG)*x[19])
f[12] = x[1] - ((m_gas5-x[7])*FM_g_CO2+x[7]*x[12])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[13] = x[2] - ((m_gas5-x[7])*FM_g_H2O+x[7]*x[13])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[14] = x[3] - ((m_gas5-x[7])*FM_g_N2+x[7]*x[14])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[15] = x[4] - ((m_gas5-x[7])*FM_g_O2+x[7]*x[15])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[16] = x[5] - (x[7]*x[16])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[17] = x[6] - (x[7]*x[17])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[18] = x[20] - x[21]/rho_ar_in
f[19] = (1/3600)*x[21] - (x[10]+x[18])
f[20] = ((x[10]+x[18])*h_in_vent + x[22]) - (x[10] + x[18])*x[23]
f[21] = x[23] - HAPropsSI('H', 'T', x[24] + 273.15, 'P', P_out_vent*1e3, 'W', omega_ar)/1e3
f[22] = x[22] - (0.000012523*x[20] + 0.054570445)
f[23] = x[25] - HAPropsSI('C', 'T', x[24] + 273.15, 'P', P_out_vent*1e3, 'W', omega_ar)/1e3
f[24] = m_gas5 - (x[7]+x[19]+x[18])
f[25] = eta_total - ((m_gas5*x[0]*(Tgas5-T0) - (x[10]+x[18])*x[25]*(x[24]-T0))
/(x[8]*PCI_RSU + x[19]*PCI_CBG))
return f
x = fsolve(block1, np.ones(26))
The code yields ValueError depending on constant values that are previously defined.
ValueError example:
ValueError: The output for key (8) with value (-nan) is outside the range of validity: (0) to (0.94145) :: inputs were:"H","T",1.3025950731911414e+02,"P",2.0132500000000000e+05,"W",1.0890000000000000e-02
If anyone can help me I will be grateful.
Thank in advance
The function you are running doesn't handle NaN values.
You can use try/except blocks to deal with it.
Or change the NaN values to a 0 (or any suitable number of your choice).
Here is a toy example to help you fix your code. You have to decide what should be the correct behavior and use one of the proposed strategies to deal with NaNs.
import bumpy as np
def f(x):
if np.isnan(x):
raise ValueError('NaN is not supported')
return x**x
test_cases = [1, 2, 3, 4, np.nan, 6, 7]
print('skip in case of error')
for x in test_cases:
try:
print(f(x))
except ValueError:
pass
print()
print('fix X in case of NaN')
for x in test_cases:
if np.isnan(x):
x = 0
print(f(x))
Output:
skip in case of error
1
4
27
256
46656
823543
fix X in case of NaN
1
4
27
256
1
46656
823543
I have an ODE system. I'm looking for a solution of the system using PyDSTool. I try to put the integration step, but I get an error.
import PyDSTool as ds
from PyDSTool import Par, Var
import time
from PyDSTool import *
# Declare names and initial values for (symbolic) parameters
varepsilon = pow(10, -2)
j = 2.5*pow(10, -5)
e = 3.0
y8 = lambda y1,y5,y7: 1 / (1 - 2 / y1) * math.sqrt(y5 ** 2 + (1 - 2 / y1) * (1 + y1 ** 2 * y7 ** 2))
E0 = lambda y1,y8: (1 - 2 / y1) * y8
Phi0 = lambda y1,y7: y1 ** 2 * y7
# Compute nontrivial boundary equilibrium initial condition from parameters (see reference for derivation)
u0 = -math.sqrt(-1 + math.sqrt(varepsilon ** 2 + 12) / varepsilon) * math.sqrt(2) / 6
v0 = 1 / (1 - 2 / e) * math.sqrt(j ** 2 + (1 - 2 / e) * (e ** 2 * u0 ** 2 + 1))
y08 = y8(y1=e, y5=j, y7=u0);
E = E0(y1=e, y8=y08); Phi = Phi0(y1=e, y7=u0)
z01, z03, z04, z05, z07, z08 = e, 0.0, 0.0, j, u0, v0
# Declare symbolic variables
z1, z3, z4, z5, z7, z8 = Var('z1'), Var('z3'), Var('z4'), Var('z5'), Var('z7'), Var('z8')
# Create Symbolic Quantity objects for definitions
p1 = -z1*z5/(z1 - 2);
p3 = -z1**2 *z7;
p4 = z8*(1 - 2/z1);
Q1 = -z5**2/(z1*(z1 - 2)) + (z8**2/z1**3 - z7**2)*(z1 - 2);
Q3 = 2*z5*z7/z1;
Q4 = 2*z5*z8/(z1*(z1 - 2));
c1 = z1*z7*varepsilon;
c3 = -z1*z5*varepsilon;
C = z7*varepsilon/z1 - z8*(1 - 2/z1);
d1 = -z1*z8*varepsilon;
d3 = z1*z5*varepsilon;
B = z1**2*z7 - z8*varepsilon*(1 - 2/z1);
Omega = 1/(c1*d3*p3+c3*d1*p4-c3*d3*p1);
# differential equations
z1dot = z5;
z3dot = z7;
z4dot = z8;
z5dot = Omega*(-Q1*c1*d3*p3 - Q1*c3*d1*p4 + Q1*c3*d3*p1 + B*c3*p4 + C*d3*p3 + E*d3*p3 - Phi*c3*p4);
z7dot = -Omega*(Q3*c1*d3*p3 + Q3*c3*d1*p4 - Q3*c3*d3*p1 + B*c1*p4 - C*d1*p4 + C*d3*p1 - E*d1*p4 + E*d3*p1 - Phi*c1*p4);
z8dot = Omega*(-Q4*c1*d3*p3 - Q4*c3*d1*p4 + Q4*c3*d3*p1 + B*c1*p3 - B*c3*p1 - C*d1*p3 - E*d1*p3 - Phi*c1*p3 + Phi*c3*p1);
# Build Generator
DSargs = args(name='Sining particle')
#print(dir(DSargs))
#DSargs.pars = [varepsilon, j, e]
DSargs.MaxNumPoints = 450
DSargs.MaxStepSize = 2e-2
DSargs.MinStepSize = 1e-5
DSargs.StepSize = e-2
DSargs.tdata = [0.0, 0.1]
DSargs.varspecs = args(z1=z1dot, z3=z3dot, z4=z4dot, z5=z5dot, z7=z7dot, z8=z8dot)
# Use eval method to get a float value from the symbolic definitions given in
# terms of parameter values
DSargs.ics = args(z1=z01, z3=z03, z4=z04, z5=z05, z7=z07, z8=z08)
ode = Generator.Vode_ODEsystem(DSargs)
t = time.time()
result = ode.compute('test')
print("time for integration: %f" %(time.time() - t))
pts = result.sample()
plt.plot(pts['t'], pts['z7'], label='x')
plt.legend()
plt.xlabel('t')
plt.show()
Through the next lines I get an the error:
DSargs.MaxNumPoints = 450
DSargs.MaxStepSize = 2e-2
DSargs.MinStepSize = 1e-5
DSargs.StepSize = e-2
Traceback (most recent call last):
File "C:\Users\mykola\Downloads\pydstool.py", line 65, in <module>
ode = Generator.Vode_ODEsystem(DSargs)
File "C:\Users\mykola\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PyDSTool\Generator\Vode_ODEsystem.py", line 47, in __init__
ODEsystem.__init__(self, kw)
File "C:\Users\mykola\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PyDSTool\Generator\ODEsystem.py", line 61, in __init__
self.checkArgs(kw)
File "C:\Users\mykola\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PyDSTool\Generator\baseclasses.py", line 1069, in checkArgs
raise PyDSTool_KeyError('Invalid keyword arguments for this class')
PyDSTool.errors.PyDSTool_KeyError: 'Invalid keyword arguments for this class'
The library PyDSTool has very little training information in internet.
What I do wrong?. And how to correctly determine the step of integration?
Objective
I am trying to symbolically solve an integral that has constant coefficients (a_w, b_IN_w, c_IN_w), which are composed of simple algebraic expressions.
What I Tried
I have tried running the code given below for an entire day, but it was still running when I checked it after a day. I have used Sympy before and I understand it may not be able to solve some complex operations, where it throws some kind of message or error indicating the problem. However, in the case described below, the program is busy running even after a day, which seems unreasonable for this problem with simple expressions. Is it possible to get the solution for the below-given expression (for q_IN_w)?
I updated Sympy to its most recent version using conda before I ran this problem.
import sympy as sym
def deg_to_rad(theta_deg):
from numpy import pi
theta_rad = (pi/180)*theta_deg
return theta_rad
r, a_w, a_o, a_g, b_IN_w, b_IN_o, b_IN_g, c_IN_2w, c_IN_2o, c_IN_2g, r_1, r_2, R, \
sigma_dia, IFT_ow, theta_IN_CA_deg, D_IN_ads_coeff, nablaP, mu_w, deltaP = \
sym.symbols('r, a_w, a_o, a_g, b_IN_w, b_IN_o, b_IN_g, c_IN_2w, c_IN_2o, c_IN_2g, r_1, r_2, R, \
sigma_dia, IFT_ow, theta_IN_CA_deg, D_IN_ads_coeff, nablaP, mu_w, deltaP')
l_IN_slip = sigma_dia/((sym.pi - deg_to_rad(theta_IN_CA_deg))**4)
W_IN_egy = IFT_ow*(1 + sym.cos(deg_to_rad(theta_IN_CA_deg)))
u_IN_s = (l_IN_slip*R*nablaP)/(2*mu_w)
u_IN_ads = (D_IN_ads_coeff/W_IN_egy)*deltaP
u_IN_s_eff = (u_IN_s - u_IN_ads)
b_IN_g = 0
b_IN_o = 2*(a_g - a_o)*(r_1**2)
b_IN_w = b_IN_o + 2*(a_o - a_w)*(r_2**2)
c_IN_2w = u_IN_s_eff - a_w*(R**2) - b_IN_w*sym.log(R)
q_IN_w = sym.integrate((a_w*(r**2) + b_IN_w*(sym.log(r)) + c_IN_2w)*(2*sym.pi*r), (r, r_2, R))
Here it finished in 30s, but it's quite the answer with the sym.pi
pi*R**4*a_w/2 - R**2*(pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**4 - 720*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**3 + 194400*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**2 - 23328000*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg + 1049760000*pi**4*D_IN_ads_coeff*deltaP*mu_w + pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**4 - 720*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**3 + 194400*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**2 - 23328000*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg + 1049760000*pi**4*IFT_ow*R**2*a_w*mu_w*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*R**2*a_w*mu_w - 524880000*IFT_ow*R*nablaP*sigma_dia*cos(pi*theta_IN_CA_deg/180) - 524880000*IFT_ow*R*nablaP*sigma_dia + 2*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) + 2*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*log(R) + pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4 - 1440*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) - 1440*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*log(R) - 720*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3 + 388800*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 388800*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*log(R) + 194400*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2 - 46656000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) - 46656000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*log(R) - 23328000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg + 2099520000*pi**4*IFT_ow*a_g*mu_w*r_1**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 2099520000*pi**4*IFT_ow*a_g*mu_w*r_1**2*log(R) + 1049760000*pi**4*IFT_ow*a_g*mu_w*r_1**2*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*a_g*mu_w*r_1**2 - 2*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) - 2*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*log(R) - pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) - pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4 + 1440*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) + 1440*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*log(R) + 720*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) + 720*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3 - 388800*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 388800*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*log(R) - 194400*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) - 194400*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2 + 46656000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) + 46656000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*log(R) + 23328000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) + 23328000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg - 2099520000*pi**4*IFT_ow*a_o*mu_w*r_1**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 2099520000*pi**4*IFT_ow*a_o*mu_w*r_1**2*log(R) - 1049760000*pi**4*IFT_ow*a_o*mu_w*r_1**2*cos(pi*theta_IN_CA_deg/180) - 1049760000*pi**4*IFT_ow*a_o*mu_w*r_1**2 + 2*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) + 2*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*log(R) + pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4 - 1440*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) - 1440*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*log(R) - 720*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3 + 388800*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 388800*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*log(R) + 194400*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2 - 46656000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) - 46656000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*log(R) - 23328000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg + 2099520000*pi**4*IFT_ow*a_o*mu_w*r_2**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 2099520000*pi**4*IFT_ow*a_o*mu_w*r_2**2*log(R) + 1049760000*pi**4*IFT_ow*a_o*mu_w*r_2**2*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*a_o*mu_w*r_2**2 - 2*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) - 2*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*log(R) - pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) - pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4 + 1440*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) + 1440*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*log(R) + 720*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) + 720*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3 - 388800*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 388800*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*log(R) - 194400*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) - 194400*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2 + 46656000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) + 46656000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*log(R) + 23328000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) + 23328000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg - 2099520000*pi**4*IFT_ow*a_w*mu_w*r_2**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 2099520000*pi**4*IFT_ow*a_w*mu_w*r_2**2*log(R) - 1049760000*pi**4*IFT_ow*a_w*mu_w*r_2**2*cos(pi*theta_IN_CA_deg/180) - 1049760000*pi**4*IFT_ow*a_w*mu_w*r_2**2)/(pi**3*IFT_ow*mu_w*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**3*IFT_ow*mu_w*theta_IN_CA_deg**4 - 720*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**3 + 194400*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**2 - 23328000*pi**3*IFT_ow*mu_w*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**3*IFT_ow*mu_w*theta_IN_CA_deg + 1049760000*pi**3*IFT_ow*mu_w*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**3*IFT_ow*mu_w) - pi*a_w*r_2**4/2 + r_2**2*(pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**4 - 720*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**3 + 194400*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg**2 - 23328000*pi**4*D_IN_ads_coeff*deltaP*mu_w*theta_IN_CA_deg + 1049760000*pi**4*D_IN_ads_coeff*deltaP*mu_w + pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**4 - 720*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**3 + 194400*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg**2 - 23328000*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*R**2*a_w*mu_w*theta_IN_CA_deg + 1049760000*pi**4*IFT_ow*R**2*a_w*mu_w*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*R**2*a_w*mu_w - 524880000*IFT_ow*R*nablaP*sigma_dia*cos(pi*theta_IN_CA_deg/180) - 524880000*IFT_ow*R*nablaP*sigma_dia + 2*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) + 2*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*log(R) + pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**4 - 1440*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) - 1440*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*log(R) - 720*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**3 + 388800*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 388800*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*log(R) + 194400*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg**2 - 46656000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) - 46656000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*log(R) - 23328000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*a_g*mu_w*r_1**2*theta_IN_CA_deg + 2099520000*pi**4*IFT_ow*a_g*mu_w*r_1**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 2099520000*pi**4*IFT_ow*a_g*mu_w*r_1**2*log(R) + 1049760000*pi**4*IFT_ow*a_g*mu_w*r_1**2*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*a_g*mu_w*r_1**2 - 2*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) - 2*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*log(R) - pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) - pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**4 + 1440*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) + 1440*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*log(R) + 720*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) + 720*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**3 - 388800*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 388800*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*log(R) - 194400*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) - 194400*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg**2 + 46656000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) + 46656000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*log(R) + 23328000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) + 23328000*pi**4*IFT_ow*a_o*mu_w*r_1**2*theta_IN_CA_deg - 2099520000*pi**4*IFT_ow*a_o*mu_w*r_1**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 2099520000*pi**4*IFT_ow*a_o*mu_w*r_1**2*log(R) - 1049760000*pi**4*IFT_ow*a_o*mu_w*r_1**2*cos(pi*theta_IN_CA_deg/180) - 1049760000*pi**4*IFT_ow*a_o*mu_w*r_1**2 + 2*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) + 2*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*log(R) + pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**4 - 1440*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) - 1440*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*log(R) - 720*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**3 + 388800*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 388800*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*log(R) + 194400*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg**2 - 46656000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) - 46656000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*log(R) - 23328000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**4*IFT_ow*a_o*mu_w*r_2**2*theta_IN_CA_deg + 2099520000*pi**4*IFT_ow*a_o*mu_w*r_2**2*log(R)*cos(pi*theta_IN_CA_deg/180) + 2099520000*pi**4*IFT_ow*a_o*mu_w*r_2**2*log(R) + 1049760000*pi**4*IFT_ow*a_o*mu_w*r_2**2*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**4*IFT_ow*a_o*mu_w*r_2**2 - 2*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*log(R)*cos(pi*theta_IN_CA_deg/180) - 2*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*log(R) - pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) - pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**4 + 1440*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*log(R)*cos(pi*theta_IN_CA_deg/180) + 1440*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*log(R) + 720*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) + 720*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**3 - 388800*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 388800*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*log(R) - 194400*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) - 194400*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg**2 + 46656000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*log(R)*cos(pi*theta_IN_CA_deg/180) + 46656000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*log(R) + 23328000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) + 23328000*pi**4*IFT_ow*a_w*mu_w*r_2**2*theta_IN_CA_deg - 2099520000*pi**4*IFT_ow*a_w*mu_w*r_2**2*log(R)*cos(pi*theta_IN_CA_deg/180) - 2099520000*pi**4*IFT_ow*a_w*mu_w*r_2**2*log(R) - 1049760000*pi**4*IFT_ow*a_w*mu_w*r_2**2*cos(pi*theta_IN_CA_deg/180) - 1049760000*pi**4*IFT_ow*a_w*mu_w*r_2**2)/(pi**3*IFT_ow*mu_w*theta_IN_CA_deg**4*cos(pi*theta_IN_CA_deg/180) + pi**3*IFT_ow*mu_w*theta_IN_CA_deg**4 - 720*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**3*cos(pi*theta_IN_CA_deg/180) - 720*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**3 + 194400*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**2*cos(pi*theta_IN_CA_deg/180) + 194400*pi**3*IFT_ow*mu_w*theta_IN_CA_deg**2 - 23328000*pi**3*IFT_ow*mu_w*theta_IN_CA_deg*cos(pi*theta_IN_CA_deg/180) - 23328000*pi**3*IFT_ow*mu_w*theta_IN_CA_deg + 1049760000*pi**3*IFT_ow*mu_w*cos(pi*theta_IN_CA_deg/180) + 1049760000*pi**3*IFT_ow*mu_w) + (2*pi*R**2*a_g*r_1**2 - 2*pi*R**2*a_o*r_1**2 + 2*pi*R**2*a_o*r_2**2 - 2*pi*R**2*a_w*r_2**2)*log(R) - (2*pi*a_g*r_1**2*r_2**2 - 2*pi*a_o*r_1**2*r_2**2 + 2*pi*a_o*r_2**4 - 2*pi*a_w*r_2**4)*log(r_2)