math - Using Wolfram Alpha in Python? -


i'm developing program in python. part of process involves solving equation in x in form ax^1.2 + bx^2.2 + cx^3.2 + dx^4.2 - s = 0, a, b, c, d , s known variables.

i've installed wolfram alpha package using pip, , working in ide pycharm. code correctly calculates value of x, think stored string, rather float, because 'answer' outputted "x = 385.279", instead of numerical value. in order use x value in further calculations, need convert float removing "x = " part. know how in python, wondering how done using wolfram alpha language?

this section of code far:

client = wf.client("app_id") #app_id app id  q = "solve 274770*x**1.2 + 8271.8*x**2.2 + 79.555*x**3.2 + 0.22184*x**4.2 -  35435557377 = 0" res = client.query(q) answer = next(res.results).text print(answer)  ra1 = answer print("ra1:", ra1)  ra2 = (k*r0**eta) / (measured_density_a*(h*ra1**0.2 + g*ra1**1.2 +  i*ra1**2.2 + e*ra1**3.2)) print("ra2", ra2) 

these variables calculated used in code:

k = 653.1494097422409 eta = 3.9074130500231186 alpha = 1.2 r0 = 92 measured_density_a = 10 measured_density_b = 7 measured_density_c = 12 power = eta-alpha 

this output when run code:

x = 385.279 ra1: x = 385.279

traceback (most recent call last): file "c:/users/nadia/pycharmprojects/particle_energy/energy_code/complete_code_wolfram.py", line 282, in ra2 = (k * r0 ** eta) / (measured_density_a * (h * ra1 ** 0.2 + g * ra1 ** 1.2 + * ra1 ** 2.2 + e * ra1 ** 3.2))

typeerror: unsupported operand type(s) ** or pow(): 'str' , 'float'

thank in advance!


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -