How do you solve a nonlinear ODE with Matlab using ode45?
65 ビュー (過去 30 日間)
古いコメントを表示
I have done this with a linear ODE which had the equation x''+(c/m)*x'+(g/L)*x = 0 where x(0) = pi/6 and x'(0) = 0
This is the function file followed by the script file I used:
function output1 = linearode(t,y)
c = 2;
m = 1;
g = 10;
L = 1;
output1 = [ y(2); -1*(c/m)*y(2)-(g/L)*y(1)];
_________________________________________________________________________________________________________
Nt = 101; %Step Size of time
ti = 0; %Initial time (sec)
tf = 10; %Final time (sec)
t = linspace(ti,tf,Nt); %Time vector (sec)
x1 = pi/6; %Initial Position (radians)
v1 = 0; %Initial Velocity (radians/s)
%Initial position and velocity for ode45 routine
initial1 = [x1, v1];
%ode45 routine where y1 is the Angular Position (degrees) of Case 1, Method 3
[t1,y1] = ode45(@linearode,t,initial1);
plot(t1,y1(:,1)*180/pi),grid on
________________________________________________________________________________________________________
These two files represent a solution using ode45 for a linear ODE. I would like to do the same with a nonlinear ODE specifically x''+(c/m)*x'+(g/L)*sin(x) = 0 where x(0) = pi/6 and x'(0) = 0. (THE DIFFERENCE IS THE USE OF THE SIN FUNCTION). How can this be done?
0 件のコメント
採用された回答
Star Strider
2014 年 12 月 6 日
You have to describe your second-order ODE as two first-order ODEs, just as you have with your first ODE. That is all that is necessary. (That’s relatively easily done, and if you don’t want to do it yourself and if you have the Symbolic Math Toolbox, you can use the odeToVectorField function and matlabFunction to do it for you.) Then integrate it with ode45 just as you have with your current ODE.
The ode45 solver shouldn’t have any problems with it. If it does, it will let you know.
6 件のコメント
その他の回答 (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!