ode45 for Higher Order Differential Equations
3 ビュー (過去 30 日間)
古いコメントを表示
I'm learning Matlab and as an exercise I have following:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036680/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036685/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036690/image.png)
on the time interval [0 20]and with integration step < 0.01. Initial conditions are x(0) = 0.44;
= 0.13;
= 0.42;
= -1.29
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036695/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036705/image.png)
To solve it I wrote the code:
f = @(t, y) [y(4); y(3); y(2); 1 - y(1)^2 - 6*y(3)];
t = [0 100];
f0 = [-0.44; 0.13; 0.42; -1.29];
[x, y] = ode45(f, t, f0);
plot(x,y, '-');
grid on
However I'm not really sure that it's correct even it launches and gives some output. Could someone please have a look and correct it if it's wrong. Also where is integration step here?
1 件のコメント
Star Strider
2022 年 6 月 18 日
編集済み: Star Strider
2022 年 6 月 18 日
The integration is performed within the ode45 function. To understand how it works to do the integration, see Algorithms and the Wikipedia article on Runge-Kutta methods.
採用された回答
Sam Chak
2022 年 6 月 18 日
編集済み: Sam Chak
2022 年 6 月 18 日
Hi @d
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036725/image.png)
A little fix on the system of 1st-order ODEs.
f = @(t, x) [x(2); x(3); x(4); 1 - x(1)^2 - 6*x(3)];
tspan = 0:0.01:20;
x0 = [0.44; 0.13; 0.42; -1.29];
[t, x] = ode45(f, tspan, x0);
plot(t, x, 'linewidth', 1.5)
grid on, xlabel('t'), ylabel('\bf{x}'), legend('x_{1}', 'x_{2}', 'x_{3}', 'x_{4}', 'location', 'best')
2 件のコメント
Sam Chak
2022 年 6 月 18 日
You are welcome, @d. The link suggested by @Star Strider has many good examples and 'tricks' to learn.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!