我想用Python解隐式方程y=(5.172*(10+4.472*y)^0.4)/(10+2*y [英] I want to solve the implicit equation y = (5.172*(10+4.472*y)^0.4)/(10+2*y) using python

查看:17
本文介绍了我想用Python解隐式方程y=(5.172*(10+4.472*y)^0.4)/(10+2*y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上涉及到求解流量方程 Q=1/nAR^(2/3)*S^(1/2)

其中in而不是深度‘y’的流量‘q’将是已知的,而深度将通过以传统方式进行初始近似来找出。

我想要的是用python语言开发一段代码,在给出初始近似时,该代码可以迭代地求解深度‘y’。

推荐答案

不适合这样的CPU密集型操作。用纯Python和迭代方法进行近似可能行不通。如果解决方案保证是整数,并且您知道它的上下界,那么您可以使用二进制搜索。但是对于实数近似,使用纯python是没有意义的。

幸运的是,有一些用于此的库。

这里有一个一行示例:

import scipy.optimize as opt
sol=opt.fsolve(lambda y:(5.172*(10+4.472*y)**0.4)/(10+2*y)-y , 0)
print(sol)

# prints [1.24179016]
# this solves the equation of (function =0)
# note that the second argument '0' doesn't mean the target value
# target value is always 0. so you need to make a (equation)=0 form
# 2nd argument means initial estimated value,
# so it doesn't matter whether you put 0 or 1 or 100 there.
# you can give a function that returns multiple equations as the first
# argument to solve multi variable equations

您必须安装Scipy库。(使用pip)

这篇关于我想用Python解隐式方程y=(5.172*(10+4.472*y)^0.4)/(10+2*y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆