ode45求解微分方程(MATLAB)


首先介紹一下ode45的格式:

[t,y] = ode45(odefun,tspan,y0)
[t,y] = ode45(odefun,tspan,y0,options)
[t,y,te,ye,ie] = ode45(odefun,tspan,y0,options)
sol = ode45(___)

這里介紹一階微分方程:

[自變量,因變量] = ode45(方程,范圍,初值);

 

舉個栗子:

 

首先創建一個func2.m函數存放方程表達式

function Biubiu = func2(h, t)
g = 9.8;
Biubiu = (10000*pi/sqrt(2*g))*(h.^(3/2) - 2*(h.^(1/2)));
end

  

接着在MATLAB命令窗口輸入:

tspan = [1 0];%函數范圍
t_1 = 0;%初值
[h,t] = ode45(@func2, hspan, t_1);
plot(h,t);%繪圖

  

 

可以豐富一下圖像,增加橫坐標名,縱坐標名和標題

xlabel('h值')
ylabel('y值')
title('一階微分方程')

  

 

相關資料訪問https://ww2.mathworks.cn/help/matlab/ref/ode45.html?s_tid=doc_ta


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM