Avoiding value Error into fsolve from scipy.optimize - python

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

Related

How do I calculate quantization error of 2 tuples in python

I'm currently trying to code Floyd-Steinberg dithering in python
When trying to add colour in Floyd-Steinberg dithering, you have to calculate the "quantization error" of 2 tuples.
How would I go about doing this?
Converting them to grayscale doesn't produce good results, and I'm not sure how I would get it to work.
I don't want help with any other part of my code, just the quantization error.
Here is my code :
from PIL import Image
import sys,math
imag = Image.open(sys.argv[1])
palette = [(0,0,0,255),(255,255,255,255),(255,0,0,255),(0,255,0,255),(0,0,255,255)]
def distance(co1, co2):
return pow(abs(co1[0] - co2[0]), 2) + pow(abs(co1[1] - co2[2]), 2)
def palcol(col,pal):
return min(pal, key=lambda x: distance(x, col))
for y in range(imag.height-1):
for x in range(imag.width-1):
oldpixel = imag.getpixel((x,y))[0] * 299/1000 + imag.getpixel((x,y))[1] * 587/1000 + imag.getpixel((x,y))[2] * 114/1000
newpixel = palcol(imag.getpixel((x,y)),palette)[0] * 299/1000 + palcol(imag.getpixel((x,y)),palette)[1] * 587/1000 + palcol(imag.getpixel((x,y)),palette)[2] * 114/1000
querror = oldpixel - newpixel
newpixel = palcol(imag.getpixel((x,y)),palette)
imag.putpixel((x,y),newpixel)
imag.putpixel((x + 1,y ),tuple([round(imag.getpixel((x + 1,y ))[0] + (querror*7/16)),round(imag.getpixel((x + 1,y ))[1] + (querror*7/16)),round(imag.getpixel((x + 1,y ))[2] + (querror*7/16)),255]))
imag.putpixel((x - 1,y + 1),tuple([round(imag.getpixel((x - 1,y + 1))[0] + (querror*3/16)),round(imag.getpixel((x - 1,y + 1))[1] + (querror*3/16)),round(imag.getpixel((x - 1,y + 1))[2] + (querror*3/16)),255]))
imag.putpixel((x ,y + 1),tuple([round(imag.getpixel((x ,y + 1))[0] + (querror*5/16)),round(imag.getpixel((x ,y + 1))[1] + (querror*5/16)),round(imag.getpixel((x ,y + 1))[2] + (querror*5/16)),255]))
imag.putpixel((x + 1,y + 1),tuple([round(imag.getpixel((x + 1,y + 1))[0] + (querror*1/16)),round(imag.getpixel((x + 1,y + 1))[1] + (querror*1/16)),round(imag.getpixel((x + 1,y + 1))[2] + (querror*1/16)),255]))
imag.show()

Infeasible solution by pulp [duplicate]

I'm trying to solve an assignment problem with pulp. The basic part of the code is as follows:
set_I = range(1, numberOfPoints)
set_J = range(1, numberOfCentroids)
tau = 0.15
Q = 15
# decision variable
x_vars = LpVariable.dicts(name="x_vars", indexs=(set_I, set_J), lowBound=0, upBound=1, cat=LpInteger)
# model name
prob = LpProblem("MIP_Model", LpMinimize)
# constraints
for i in set_I:
prob += lpSum(x_vars[i][j] for j in set_J) == 1, ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) >= 1, ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) <= Q*(1-tau), ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) >= Q*(1+tau), ""
# objective
prob += lpSum(d[i, j]*x_vars[i][j] for i in set_I for j in set_J)
prob.solve()
The result is like this:
Problem MODEL has 31 rows, 76 columns and 304 elements
Coin0008I MODEL read with 0 errors
Problem is infeasible - 0.01 seconds
Option for printingOptions changed from normal to all
However, the problem is not infeasible and results are obtained with other solvers.
I wonder if there is a syntax error and is the problem caused by this?
I have asked a similar question in the next link:
Infeasible solution by pulp
When I run the problem locally, with d a matrix of ones, 20 points, and 3 centroids. It also becomes infeasible for me. Look at the constraints:
_C22: x_vars_10_1 + x_vars_11_1 + x_vars_12_1 + x_vars_13_1 + x_vars_14_1
+ x_vars_15_1 + x_vars_16_1 + x_vars_17_1 + x_vars_18_1 + x_vars_19_1
+ x_vars_1_1 + x_vars_2_1 + x_vars_3_1 + x_vars_4_1 + x_vars_5_1 + x_vars_6_1
+ x_vars_7_1 + x_vars_8_1 + x_vars_9_1 <= 12.75
_C23: x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2 <= 12.75
_C24: x_vars_10_1 + x_vars_11_1 + x_vars_12_1 + x_vars_13_1 + x_vars_14_1
+ x_vars_15_1 + x_vars_16_1 + x_vars_17_1 + x_vars_18_1 + x_vars_19_1
+ x_vars_1_1 + x_vars_2_1 + x_vars_3_1 + x_vars_4_1 + x_vars_5_1 + x_vars_6_1
+ x_vars_7_1 + x_vars_8_1 + x_vars_9_1 >= 17.25
_C25: x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2 >= 17.25
You require
x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2
to be greater than 17.25 and smaller than 12.75 at the same time. That's not possible, of course.

How to convert symbolic expressions to float in Python?

Now i m trying to solve 6th order of nonlinear equations.
For solving this problem, 'fsolve' is the best module for my situation.
But i have a problem for using this 'fsolve'.
My Equations below : eq1, eq2, eq3, eq4, eq5, eq6
U = (E*h/32)*(pi**4*K3+8*pi**2*K4+16*J2-pi**4/b*K1**2-8*pi**2/b*K1*J1)+pi**2/2*D*((K1*K2)**0.5+(1-v)*K5-v*K6)+F/(4*b)*pi**2*K1
eq1 = diff(U,b_1)
eq2 = diff(U,b_2)
eq3 = diff(U,b_3)
eq4 = diff(U,b_4)
eq5 = diff(U,b_5)
eq6 = diff(U,b_6)
Now i m gonna try to define functions:
def functions(v):
b_1 = v[0]
b_2 = v[1]
b_3 = v[2]
b_4 = v[3]
b_5 = v[4]
b_6 = v[5]
return eq1,eq2,eq3,eq4,eq5,eq6
Until now, all of code is perfectly completed.
But next, I got a error code for 'fsolve'
x0 = [0.1,0.1,0.1,0.1,0.1,0.1]
solutions = fsolve(functions,x0)
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\sympy\core\expr.py", line 327, in __float__
raise TypeError("can't convert expression to float")
TypeError: can't convert expression to float
Traceback (most recent call last):
File "C:\Users\user\Desktop\-----\trial.py", line 97, in <module>
solutions = fsolve(functions,x0)
File "C:\Users\user\anaconda3\lib\site-packages\scipy\optimize\minpack.py", line 147, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "C:\Users\user\anaconda3\lib\site-packages\scipy\optimize\minpack.py", line 225, in _root_hybr
ml, mu, epsfcn, factor, diag)
error: Result from function call is not a proper array of floats.
Actually i don't know exactly meaning about 'array of floats'.
The eq1~eq6 is really complicated expressions. For example (eq1):
519749583.393768*b_1**3 + 519749583.393768*b_1**2*b_2 + 311849750.036261*b_1**2*b_3 + 222749821.454472*b_1**2*b_4 + 173249861.131256*b_1**2*b_5 + 141749886.380119*b_1**2*b_6 + 589049527.846271*b_1*b_2**2 + 920699262.011818*b_1*b_2*b_3 + 742499404.84824*b_1*b_2*b_4 + 619499503.439037*b_1*b_2*b_5 + 530653420.807624*b_1*b_2*b_6 + 395009683.379264*b_1*b_3**2 + 672299461.117134*b_1*b_3*b_4 + 581053380.409443*b_1*b_3*b_5 + 510299590.968427*b_1*b_3*b_6 + 296183828.527375*b_1*b_4**2 + 524699579.42609*b_1*b_4*b_5 + 469323153.224931*b_1*b_4*b_6 + 236661575.009363*b_1*b_5**2 + 429394392.660243*b_1*b_5*b_6 + 196977114.839905*b_1*b_6**2 + 39642.9110110422*b_1 + 193049845.260542*b_2**3 + 482129613.548124*b_2**2*b_3 + 406949673.808743*b_2**2*b_4 + 350618949.729969*b_2**2*b_5 + 307488215.070719*b_2**2*b_6 + 420149663.228267*b_2*b_3**2 + 732095017.5835*b_2*b_3*b_4 + 645437944.186494*b_2*b_3*b_5 + 575987321.121736*b_2*b_3*b_6 + 326318969.207663*b_2*b_4**2 + 585464236.60242*b_2*b_4*b_5 + 529609601.687166*b_2*b_4*b_6 + 266189415.118358*b_2*b_5**2 + 486862510.0121*b_2*b_5*b_6 + 224616040.694387*b_2*b_6**2 - 29192.3833775011*b_2 + 125272976.510293*b_3**3 + 334349732.001359*b_3**2*b_4 + 299655189.675087*b_3**2*b_5 + 270932940.727941*b_3**2*b_6 + 302393649.018531*b_3*b_4**2 + 549176644.826696*b_3*b_4*b_5 + 501838635.183477*b_3*b_4*b_6 + 252001834.206563*b_3*b_5**2 + 464613445.578031*b_3*b_5*b_6 + 215729827.081362*b_3*b_6**2 - 28558.195613361*b_3 + 92286363.2746599*b_4**3 + 253972873.350655*b_4**2*b_5 + 234063996.922265*b_4**2*b_6 + 234970783.525745*b_4*b_5**2 + 436229928.976872*b_4*b_5*b_6 + 203716223.26551*b_4*b_6**2 - 24903.5955817128*b_4 + 72968765.0411644*b_5**3 + 204424758.743579*b_5**2*b_6 + 191897759.069662*b_5*b_6**2 - 21706.6337724143*b_5 + 60314467.7838601*b_6**3 - 19178.52782655*b_6 + 52.9828871992195*((35.720610813872*b_2**2 + 142.882443255488*b_2*b_3 + 214.323664883232*b_2*b_4 + 285.764886510976*b_2*b_5 + 357.20610813872*b_2*b_6 + 257.188397859878*b_3**2 + 918.529992356708*b_3*b_4 + 1333.56947038455*b_3*b_5 + 1753.55725813553*b_3*b_6 + 893.0152703468*b_4**2 + 2727.7557348775*b_4*b_5 + 3709.44804605594*b_4*b_6 + 2154.22760600582*b_5**2 + 6001.0626167305*b_5*b_6 + 4254.9551116524*b_6**2)*(0.482*b_1**2 + 0.321333333333333*b_1*b_2 + 0.1928*b_1*b_3 + 0.137714285714286*b_1*b_4 + 0.107111111111111*b_1*b_5 + 0.0876363636363637*b_1*b_6 + 0.0964*b_2**2 + 0.137714285714286*b_2*b_3 + 0.107111111111111*b_2*b_4 + 0.0876363636363637*b_2*b_5 + 0.0741538461538462*b_2*b_6 + 0.0535555555555556*b_3**2 + 0.0876363636363637*b_3*b_4 + 0.0741538461538462*b_3*b_5 + 0.0642666666666667*b_3*b_6 + 0.0370769230769231*b_4**2 + 0.0642666666666667*b_4*b_5 + 0.0567058823529412*b_4*b_6 + 0.0283529411764706*b_5**2 + 0.0507368421052632*b_5*b_6 + 0.022952380952381*b_6**2))**0.5*(0.964*b_1 + 0.321333333333333*b_2 + 0.1928*b_3 + 0.137714285714286*b_4 + 0.107111111111111*b_5 + 0.0876363636363637*b_6)/(0.482*b_1**2 + 0.321333333333333*b_1*b_2 + 0.1928*b_1*b_3 + 0.137714285714286*b_1*b_4 + 0.107111111111111*b_1*b_5 + 0.0876363636363637*b_1*b_6 + 0.0964*b_2**2 + 0.137714285714286*b_2*b_3 + 0.107111111111111*b_2*b_4 + 0.0876363636363637*b_2*b_5 + 0.0741538461538462*b_2*b_6 + 0.0535555555555556*b_3**2 + 0.0876363636363637*b_3*b_4 + 0.0741538461538462*b_3*b_5 + 0.0642666666666667*b_3*b_6 + 0.0370769230769231*b_4**2 + 0.0642666666666667*b_4*b_5 + 0.0567058823529412*b_4*b_6 + 0.0283529411764706*b_5**2 + 0.0507368421052632*b_5*b_6 + 0.022952380952381*b_6**2) + (-1.28102213260338e-7*b_2 - 3.20255533150846e-8*b_3 - 3.20255533150846e-8*b_4 - 1.60127766575423e-8*b_6)*(0.482*b_1**2 + 0.321333333333333*b_1*b_2 + 0.1928*b_1*b_3 + 0.137714285714286*b_1*b_4 + 0.107111111111111*b_1*b_5 + 0.0876363636363637*b_1*b_6 + 0.0964*b_2**2 + 0.137714285714286*b_2*b_3 + 0.107111111111111*b_2*b_4 + 0.0876363636363637*b_2*b_5 + 0.0741538461538462*b_2*b_6 + 0.0535555555555556*b_3**2 + 0.0876363636363637*b_3*b_4 + 0.0741538461538462*b_3*b_5 + 0.0642666666666667*b_3*b_6 + 0.0370769230769231*b_4**2 + 0.0642666666666667*b_4*b_5 + 0.0567058823529412*b_4*b_6 + 0.0283529411764706*b_5**2 + 0.0507368421052632*b_5*b_6 + 0.022952380952381*b_6**2) + (1.18477228028269e-9*b_1 + 6.14508444130024e-10*b_2 + 4.60881333097518e-10*b_3 + 1.53627111032506e-10*b_4 + 1.53627111032506e-10*b_5)*(78.9568352087149*b_1**2 + 52.6378901391433*b_1*b_2 + 31.582734083486*b_1*b_3 + 22.5590957739185*b_1*b_4 + 17.5459633797144*b_1*b_5 + 14.3557882197663*b_1*b_6 + 15.791367041743*b_2**2 + 22.5590957739185*b_2*b_3 + 17.5459633797144*b_2*b_4 + 14.3557882197663*b_2*b_5 + 12.1472054167254*b_2*b_6 + 8.77298168985721*b_3**2 + 14.3557882197663*b_3*b_4 + 12.1472054167254*b_3*b_5 + 10.5275780278287*b_3*b_6 + 6.07360270836269*b_4**2 + 10.5275780278287*b_4*b_5 + 9.2890394363194*b_4*b_6 + 4.6445197181597*b_5**2 + 8.31124581144368*b_5*b_6 + 3.75984929565309*b_6**2) + (0.964*b_1 + 0.321333333333333*b_2 + 0.1928*b_3 + 0.137714285714286*b_4 + 0.107111111111111*b_5 + 0.0876363636363637*b_6)*(-1.28102213260338e-7*b_1*b_2 - 3.20255533150846e-8*b_1*b_3 - 3.20255533150846e-8*b_1*b_4 - 1.60127766575423e-8*b_1*b_6 - 1.60127766575423e-8*b_2**2 - 3.20255533150846e-8*b_2*b_3 - 1.60127766575423e-8*b_2*b_5 - 8.00638832877115e-9*b_3**2 + 1.60127766575423e-8*b_3*b_4 - 8.00638832877115e-9*b_3*b_6 - 8.00638832877115e-9*b_4*b_5 + 8.00638832877115e-9*b_4*b_6 + 4.00319416438558e-9*b_5**2 - 8.00638832877115e-9*b_5*b_6 + 4.00319416438558e-9*b_6**2 + 41123.3516712057) - 129937395.848442*(4*b_1 + 1.33333333333333*b_2 + 0.8*b_3 + 0.571428571428572*b_4 + 0.444444444444445*b_5 + 0.363636363636364*b_6)*(b_1**2 + 0.666666666666667*b_1*b_2 + 0.4*b_1*b_3 + 0.285714285714286*b_1*b_4 + 0.222222222222222*b_1*b_5 + 0.181818181818182*b_1*b_6 + 0.2*b_2**2 + 0.285714285714286*b_2*b_3 + 0.222222222222222*b_2*b_4 + 0.181818181818182*b_2*b_5 + 0.153846153846154*b_2*b_6 + 0.111111111111111*b_3**2 + 0.181818181818182*b_3*b_4 + 0.153846153846154*b_3*b_5 + 0.133333333333333*b_3*b_6 + 0.076923076923077*b_4**2 + 0.133333333333333*b_4*b_5 + 0.117647058823529*b_4*b_6 + 0.0588235294117647*b_5**2 + 0.105263157894737*b_5*b_6 + 0.0476190476190477*b_6**2) + (157.91367041743*b_1 + 52.6378901391433*b_2 + 31.582734083486*b_3 + 22.5590957739185*b_4 + 17.5459633797144*b_5 + 14.3557882197663*b_6)*(5.92386140141343e-10*b_1**2 + 6.14508444130024e-10*b_1*b_2 + 4.60881333097518e-10*b_1*b_3 + 1.53627111032506e-10*b_1*b_4 + 1.53627111032506e-10*b_1*b_5 + 2.30440666548759e-10*b_2**2 + 1.53627111032506e-10*b_2*b_3 + 1.53627111032506e-10*b_2*b_4 + 1.53627111032506e-10*b_2*b_6 + 7.6813555516253e-11*b_3**2 - 7.6813555516253e-11*b_3*b_4 + 7.6813555516253e-11*b_3*b_6 + 7.6813555516253e-11*b_4*b_5 + 7.6813555516253e-11*b_4*b_6 + 3.84067777581265e-11*b_5**2 - 251.041666666667)
I must solve such theses 6 equations.
But " Result from function call is not a proper array of floats. " error message comes out.
Is there anyone who help my code?
I'm Python beginning, so Plz understane me

Python Sympy: Simple operations busy running even after a day

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)

SyntaxError when running program

I have to make a calculator with argv.sys. When I run my code I keep getting this error:
>>> "C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
File "<stdin>", line 1
"C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
^
SyntaxError: invalid syntax
>>>
Here is my program:
import sys
import math
def area_rectangle(x,y,widht,height):
return (widht*height)
def xy_centroid_rectangle(x,y):
return (k + l * 0.5)
#def area_circle(x,y,r):
#return (r*r*math.pi)
#def xy_centroid_circle(k,r):
# return ((4 * r / 3 * math.pi) * 2)
#def area_half_circle(x,y,r):
# return (r * r * math.pi / 2)
#def xy_centroid_half_circle(k,r):
# return (4 * r / 3 * math.pi)
#def area_right_triangle(x,y,a,h):
# return (a * h / 2)
#def xy_centroid_right_triangle(k,l):
# return (a + h + math.sqrt((a * a) + (h * h)))
x = 0
y = 0
a = 0
fx = 0
fy = 0
f = 0
i = 1
while i < len(sys.argv):
vz = sys.argv[i]
print i
print vz
if sys.argv[i + 1] == "rect":
f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
i += 6
#if sys.argv[i + 1] == "circ":
#f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
#fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
#i += 5
#if sys.argv[i + 1] == "halfcirc":
#f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
#fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
#i += 5
#if sys.argv[i + 1] == "righttri":
#f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
#fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
#i += 6
if vz == "+":
x = (x * a + fx * f) / (a + f)
y = (y * a + fy * f) / (a + f)
a = a + f
if vz == "-":
x = (x * a - fx * f) / (a - f)
y = (y * a - fy * f) / (a - f)
a = a - f
print x
print y
print a
Why am I getting this error?
That's not how you run a python program. Open a CMD (Windows) prompt and write your command line there. You'll probably need to add python in front too.

Categories

Resources