How do you solve a nonlinear ODE with Matlab using ode45?
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!