Re: [問題] 如何將user輸入的變數帶入ode中求解?已回收

看板MATLAB作者 (摸魚中)時間12年前 (2011/08/17 18:33), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
function 的寫法可以把ka,kb放進去 function dy=test(t,y,ka,kb) dy=zeros(3,1); dy(1)=-ka*y(1); dy(2)=ka*y(1)-kb*y(2); dy(3)=kb*y(2); end 使用ode solver參考以下寫法 % Time (假設計算時間到10) tspan = [0 10]; % Initial Conditions: y0 = [a0; 0; 0]; % Solve the problem using ode45 [tout,yout]=ode45(@(t,y) test(t,y,ka,kb) , tspan,y0); ※ 引述《band33 (時鐘)》之銘言: : 先說明一下題目 : 目前有三個方程式如下: : dA/dt=-ka*A A(0)=a0 : dI/dt=ka*A-kb*I I(0)=0 : dP/dt=kb*I P(0)=0 : a0、ka、kb這三個都是要使用者自行輸入的變數 : 然後帶入ode中求解 : 我目前只會做到先自行將三個變數設定一個值去計算 : 程式如下: (目前是先另a0=10,ka=1,kb=2) : function dy=test(t,y) : dy=zeros(3,1); : dy(1)=-1*y(1); : dy(2)=1*y(1)-2*y(2); : dy(3)=2*y(2); : end -- --------------------------------------------------------------------- a new scientific truth does not triumph by convincing its opponents, but rather because its opponents eventually die and a new generation grows up that's familiar with it. Max Planck --------------------------------------------------------------------- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.21.126 ※ 編輯: perceval 來自: 140.116.21.126 (08/17 18:34)

08/17 19:21, , 1F
感謝解答!!!!
08/17 19:21, 1F
文章代碼(AID): #1EIvZ-_q (MATLAB)
文章代碼(AID): #1EIvZ-_q (MATLAB)