Graphing a nonlinear 2nd order differential equation?
4 views (last 30 days)
Show older comments
I've searched around for a similar solution to what I'm looking for but I'm terrible at debugging. I need to graph this nonlinear 2nd order differential equation:
g = 9.81
m = 15000/g
L = 1.5 meters
J = m*L^2
J*theta_dd + m*L*g*sin(theta) = 0
0 Comments
Answers (1)
Ameer Hamza
on 19 Oct 2020
See ode45(): https://www.mathworks.com/help/matlab/ref/ode45.html espically the example titled "Solve Nonstiff Equation".
IC = [1; 0]; % initial condition
tspan = [0 10];
[t, theta] = ode45(@odefun, tspan, IC);
plot(t, theta);
legend({'$\theta$', '$\dot\theta$'}, 'FontSize', 16, 'Interpreter', 'latex');
function dtheta = odefun(t, theta)
% theta(1) = theta, theta(2) = theta_dot
g = 9.81;
m = 15000/g;
L = 1.5;
J = m*L^2;
dtheta1 = theta(2);
dtheta2 = -m*L*g*sin(theta(1))/J;
dtheta = [dtheta1; dtheta2];
end
2 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!