解决一个隐式方程Python [英] Solve an implicit equation Python
本文介绍了解决一个隐式方程Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个代码来解决"y"问题.下式中的相对误差为%1:
I want to write a code to solve for "y" with relative error %1 in equation below:
在等式中,我们具有值" b = 2,x = 1,n = 0.015,S_0 = 0.002,Q = 21
".和y应该计算出来.
In the equation we have the values of "b=2, x=1, n=0.015, S_0=0.002, Q=21
" and y should be calculated.
我写这段代码:
b=float(input('b='))
x=float(input('x= '))
n=float(input('n= '))
s=float(input('S_0= '))
Q=float(input('Q= '))
Q=(1/n)*((y*(b+x*y))**(5/3))/((b+2*y*(1+x**2)**(1/2))**(2/3)))*s
print(y)
它不起作用.
我不熟悉如何在python中求解隐式方程.如果不是隐式的,我可以写关于y的方程,然后写输入.但是在这里我不知道该怎么办.
I am not familiar how to solve the implicit equation in python. if it wasn't implicit I could write the equation with respect to y then write inputs. but here I don't know what I should do.
推荐答案
您可以重新定义方程式,方法是像下面的f(y)一样定义,然后用fsolve找到它的根
You can rephrase your equation by defining like below f(y) and then find the root of it with fsolve
from scipy.optimize import fsolve
def f(y,b=2,x=1,n=0.015,S_0=0.002,Q=21):
return (1/n)*((y*(b+x*y))**(5/3))/((b+2*y*(1+x**2)**(1/2))**(2/3))*S_0-Q
a=fsolve(f,1)
print(a)
print(f(a))
这篇关于解决一个隐式方程Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文