Euler, Runge Kutta, and ODE45

6 ビュー (過去 30 日間)
fernando piedra
fernando piedra 2020 年 11 月 5 日
回答済み: James Tursa 2020 年 11 月 5 日
Hi so i have to create a program capable of pick the function that the user wants to utiliezed, if user wants to calculate the function base using euler method the program will select Eulers Method and so on. I know how to excute them all in different mfiles but im not sure how to put them all in one mfile. I also need another mfile where all the constant are gonna be
%RK 4TH ORDER
for j=1:n
k1=f3(x(j),y2(j));
k2=f3(x(j)+0.125,y2(j)+k1*0.125);
k3=f3(x(j)+0.125,y2(j)+k2*0.125);
k4=f3(x(j)+0.125,y2(j)+k3*0.125);
y2(j+1)=y2(j)+(0.25/6)*(k1+2*(k2+k3)+k4);
x(j+1)=x(j)+h;
end
%EULERS METHOD
for i=1:n
y(i+1)=y(i)+0.25*f1(x(i),y(i));
x(i+1)=x(i)+0.25;
end
%ODE_45
fun=@(t,y)y*(t^2-1.1)
[t,y]=ode45(fun,[0 2],1)
  1 件のコメント
James Tursa
James Tursa 2020 年 11 月 5 日
Your RK4 code has an error. This line:
k4=f3(x(j)+0.125,y2(j)+k3*0.125);
should be this
k4=f3(x(j)+0.25,y2(j)+k3*0.25);

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2020 年 11 月 5 日
You could use a switch control block to run the method selected.

その他の回答 (0 件)

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by