Second Order ODE basics?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi there... I'm a bit confused on how to solve 2nd order ODE's in Matlab. I feel like I can correctly reduce the 2nd order system to a 1st order system on pencil and paper, but when I go to Matlab, things don't work out.
For example, I'm trying to solve:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153946/image.jpeg)
and I have the code:
f = @(x) [x(2);sin(x)-x(1)-x(2)];
tSpan = [0 10];
initial = [1;0];
[t,y] = ode23(f,tSpan,initial)
but I can't figure out how to finish it. I feel like I'm interpreting the "x(1)" and "x(2)" incorrectly. On paper, those are the subscripts of my "new" variables.
Any help is appreciated! :)
0 件のコメント
回答 (1 件)
Star Strider
2014 年 8 月 4 日
You’re almost there. The ODE function needs to return a value for your independent variable as well as the derivative, and the argument to sin needs to be x(1). Otherwise your essential maths for converting the second-order ODE to two first-order ODEs is correct, so you can relax as far as that goes.
This works:
f = @(t,x) [x(2); sin(x(1))-x(1)-x(2)];
参考
カテゴリ
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!