[英]Python loop only printing final loop of the dataframe as output to Excel
[英]Printing only the final odeint output
抱歉,這可能是一個很愚蠢的問題,但是我想問一問,在odeint中求解耦合微分方程時,是否可以僅輸出最終輸出值? 實際上,我正在嘗試為隨機生成的時間間隔求解兩個耦合的微分方程,並僅獲取每個間隔的最終輸出。
y值數組的最后一個元素是y[-1]
。 例如:
import numpy as np
import scipy.integrate as si
def F(y, t):
return [y[1], y[0]]
t = np.arange(0, 1, 0.001)
y = si.odeint(F, [1, 0], t)
print(y[-1])
返回[ 1.54190626 1.17365875]
。 該系統的精確解是y(t)= [cosh(t),sinh(t)]; 顯示的數字相當接近cosh(1)和sinh(1)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.