简体   繁体   中英

Using sympy to solve an equation, python

I want to solve the below using Pythons sympy module instead of adapting what if have hand written. The result is x=26.8.

在此处输入图像描述

Any help appreciated.

Tks

EDIT:

my equation without sympy:

def cal_equ(total_vel=1.23, vel_vent_mg=17.74, vel_vent_tg=28.45, const=105):
    a = (const / vel_vent_tg / const) + (1 / vel_vent_mg)
    b = (total_vel - const / vel_vent_tg)
    return b / a
from sympy import *
# create a symbol: it represents your unkown
x = symbols("x")
# create your constants
total_vel=1.23
vel_vent_mg=17.74
vel_vent_tg=28.45
const=105
# there are many ways to create an equation.
# here we create an equality, something that states that
# the left hand side is equal to the right hand side
eq = Eq((const - x) / vel_vent_tg - x / vel_vent_mg, total_vel)
# finally, we use the solve function to solve for the equation for x
sol = solve(eq, x)
sol[0].n()
# out: 26.8871034856029

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM