常微分方程數值解實驗報告

2021-03-04 00:17:20 字數 2622 閱讀 1450

2023年10月17日

實驗目的:

1.通過用matlab程式設計運用euler方法及其改進方法求解常微分方程初值問題,更進一步掌握常微分方程及其數值解法課程的理論內容,加深對數值解法的理解。

2.熟悉matlab程式設計環境。

實驗內容:

1.實驗題目

運用euler方法及其改進方法求解常微分方程初值問題,具體問題是。求滿足初值條件的解:。

2.設計思想

在能夠獲得精確解的題目抽取題目,分別應用euler方法、euler改進方法求解數值結果,將所得結果列表或者畫圖,參照精確結果,對euler方法、euler改進方法的計算誤差進行分析。

實驗原理:

euler方法:

euler改進方法:

1.euler方法程式:

%fun為目標函式字串

%x0為自變數初始值。

%y0為fun(x0);

%bou=[a,b]自變數區間

%h為步長

fun='(y+sin(x))/cos(x)';

bou=[1,6];

a=bou(1);

b=bou(2);

x0=1;

y0=1;

h=0.05;

n=ceil((b-a)/h);

xx=linspace(a,b,n+1)'; yy=zeros(1,n+1)';

lengthx=length(xx);

xx(1)=x0;yy(1)=y0

for i=2:n+1

x=xx(i-1);y=yy(i-1);

k=eval(fun

yy(i)=yy(i-1)+h*k

endys=dsolve('dy=(y+sin(x))/cos(x)','y(1)=1','x');

for i=1:lengthx

x=xx(i);

exacty(i)=eval(ys);

endyy=exacty';

yend=[xx,yy,yy]

p=plot(xx,yend(:,2),'k-o','linewidth',1,...

markeredgecolor','k',...

marke***cecolor','g',...

markersize',4);

hold on;

pp=plot(xx,yend(:,3),'r-.+','linewidth',0.8,...

markeredgecolor','r',...

marke***cecolor','m',...

markersize',6);

legend([p,pp],'eula','jiequejie');

2.euler改進方法程式

%fun為目標函式字串

%x0為自變數初始值。

%y0為fun(x0);

%bou=[a,b]自變數區間

%h為步長

fun='(y+sin(x))/cos(x)';

bou=[1,6];

a=bou(1);

b=bou(2);

x0=1;

y0=1;

h=0.05;

n=ceil((b-a)/h);

xx=linspace(a,b,n+1)'; yy=zeros(1,n+1)';

lengthx=length(xx);

xx(1)=x0;yy(1)=y0

for i =2:n+1

x=xx(i-1);y=yy(i-1);

k1=eval(fun);

x=xx(i);y=yy(i-1)+h*k1;

k2=eval(fun);

yy(i)=yy(i-1)+h/2*(k1+k2

endys=dsolve('dy=(y+sin(x))/cos(x)','y(1)=1','x');

for i=1:lengthx

x=xx(i);

exacty(i)=eval(ys);

endyy=exacty';

yend=[xx,yy,yy]

p=plot(xx,yend(:,2),'k-o','linewidth',1,...

markeredgecolor','k',...

marke***cecolor','g',...

markersize',4);

hold on;

pp=plot(xx,yend(:,3),'r-.+','linewidth',0.8,...

markeredgecolor','r',...

marke***cecolor','m',...

markersize',6);

legend([p,pp],'gjeula','jingquejie');

n=ceil((b-a)/h);

xx=linspace(a,b,n+1)'; yy=zeros(1,n+1

xx(1)=x0;yy(1)=y0;

實驗結果:

euler方法求解圖形

euler改進方法求解圖形

如圖所示,在處有奇點,euler改進方法更吻合。

實驗體會:

通過這次課內試驗學會了通過運用euler方法及其改進方法求解常微分方程初值問題,並畫出了圖形,感覺學會了很多。

常微分方程數值解實驗報告

學院 數學與資訊科學 專業 資訊與計算科學 姓名 鄭思義 學號 201216524 課程 常微分方程數值解 實驗一 常微分方程的數值解法 1 分別用euler法 改進的euler法 預報校正格式 和s k法求解初值問題。h 0.1 並與真解作比較。1.1實驗 尤拉法 function x,y nae...

MATLAB實驗報告 常微分方程數值解

專業序號姓名日期 實驗3 常微分方程數值解 實驗目的 1 掌握用matlab求微分方程初值問題數值解的方法 2 通過例項學習微分方程模型解決簡化的實際問題 3 了解尤拉方法和龍格庫塔方法的基本思想。實驗內容 用尤拉方法和龍格庫塔方法求下列微分方程初值問題的數值解,畫出解的圖形,對結果進行分析比較 解...

微分方程數值解實驗

課程設計報告 班級姓名學號 成績 2017年 6月 21 日 目錄一 摘要 1 二 常微分方程數值解 2 2.1 4階runge kutta法和adams4階外插法的基本思路 2 2.2 演算法流程圖 2 2.3 用matlab編寫源程式 2 2.4 常微分方程數值解法應用舉例 4 三 常係數擴散方...