亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求解微分方程但出現錯誤“'Add'對象不可調用”。我正在使用 Jupyter 筆記本

求解微分方程但出現錯誤“'Add'對象不可調用”。我正在使用 Jupyter 筆記本

素胚勾勒不出你 2023-05-09 15:13:59
為了更清楚,我想繪制鐘擺阻尼振蕩的二階微分方程的解。鏈接到有關所用方程式的維基百科:https ://en.wikipedia.org/wiki/Harmonic_oscillatorfrom sympy.interactive import printingprinting.init_printing(use_latex=True)import numpy as npimport scipy as spfrom sympy import*mport sympy as syp`from scipy.integrate import odeintimport matplotlib.pyplot as pltt=syp.Symbol('t')x=syp.Function('x')(t)m=2.0k=5.0a=0.5z=a/(2.0*np.sqrt(m*k))w=np.sqrt(k/m)eq=x.diff(t,t)+2.0*z*w*x.diff(t)+w**2.0*xdsolve(eq,t,0,ics={eq(1.0):0,eq(2.0):5})
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

您沒有ics按預期構造參數:


In [6]: dsolve(eq, ics={x.subs(t, 1.0): 0, x.subs(t, 2.0): 5})                                                                                 

Out[6]: 

                                                                                                 -0.125?t

x(t) = (-0.0346285740992263?sin(1.57619002661481?t) - 6.42012708343871?cos(1.57619002661481?t))?? 

如果你不使用浮點數,答案會更好(主觀地)。此外,我發現將變量保留x為函數x而不是應用函數更自然x(t),例如:


In [15]: x = Function('x')                                                                                                                     


In [16]: x                                                                                                                                     

Out[16]: x


In [17]: x(t)                                                                                                                                  

Out[17]: x(t)


In [18]: eq = x(t).diff(t, 2) + x(t).diff(t)/4 + 5*x(t)/2                                                                                      


In [19]: eq                                                                                                                                    

Out[19]: 

         d                   

         ──(x(t))     2      

5?x(t)   dt          d       

────── + ──────── + ───(x(t))

  2         4         2      

                    dt       


In [20]: dsolve(eq, x(t), ics={x(1): 0, x(2): 5})                                                                                              

Out[20]: 

       ?   1/4    ?√159?t?                     ?  -t 

       ?5??   ?sin?──────?                     ?  ───

       ?          ?  8   ?      1/4    ?√159?t??   8 

x(t) = ?────────────────── - 5??   ?cos?──────????   

       ?       ?√159?                  ?  8   ??     

       ?    tan?────?                          ?     

       ?       ? 8  ?                          ? 


查看完整回答
反對 回復 2023-05-09
  • 1 回答
  • 0 關注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號