numpy 用python求解一个未知参数的数学表达式

bvjxkvbb  于 11个月前  发布在  Python
关注(0)|答案(1)|浏览(135)

我有个等式
x1c 0d1x的数据
我想用Python来解t。首先,我应该在这个等式中说:

  • <<h r ai hint T*=1000 τ =t/t*>>*

在我问这个问题之前,我在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

字符串

c6ubokkw

c6ubokkw1#

>>> 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

字符串

相关问题