使用 python 求解特定未知参数的数学表达式

问题描述 投票:0回答:1

我有这个方程

并且想用Python解决

t
numpy
。首先我应该说,在这个等式中:

<>

已知。在我在这里问问题之前,我在

numpy
中使用了符号方法:我将
t
解释为符号,但我得到了这个

Error :cannot convert expression to float

我为有

t
并且我想计算
h
的情况编写的代码在这里:

def h_t(h=None,t=None):
    if h==None:
        term1 = np.sum([coeav[i] / (i + 1) * (t/1000)**(i + 1) for i in range(7)])
        term2 = coeav[7] * np.log(t/1000)
        term3 = np.sum([(coeav[i] / (7 - i)) * (1/(t/1000))**(i - 7) for i in range(8, 13)])
    elif t==None:
        
        
        return ((term1+term2+term3)*1000+hint/r)*r
python numpy sympy symbols equation
1个回答
0
投票
>>> from sympy import *
>>> coaev=[17.190126419067383, -11.550975799560547, 7.005699634552002, -2.862142
80128479, 0.7931802868843079, -0.13392554223537445, 0.010209172032773495, -8.967
597007751465, 3.3796420097351074, -0.7651314735412598 ,0.10340806096792221 ,-0.0
07709052879363298 ,0.0002440817333990708]; r= 8.31415; h=17609
>>> coeav=coaev
>>> var('hint t')
(hint, t)
>>> term1 = sum([coeav[i] / (i + 1) * (t/1000)**(i + 1) for i in range(7)])
>>> term2 = coeav[7] * log(t/1000)
>>> term3 = sum([(coeav[i] / (7 - i)) * (1/(t/1000))**(i - 7) for i in range(8,
13)])
>>> eq = ((term1+term2+term3)*1000+hint/r)*r

Look for a good guess near solution

>>> eq.subs(hint,h).subs(t,1).n()
-390126303482586.
>>> eq.subs(hint,h).subs(t,11).n()
-1616907300.09601
>>> eq.subs(hint,h).subs(t,111).n()
73731.7541309398

OK, got a sign change so guess in the middle

>>> nsolve(eq.subs(hint,h),50)  # assuming you mean hint = h
54.5730717247901
© www.soinside.com 2019 - 2024. All rights reserved.