Solving second order ODEs
% 2nd order ordinary differential equation (ODE)
clear all
close all
clc
b = 0.05; % damping co-efficient
m = 0.1; % mass - kg
g = 9.81; % gravity - m/(s^2)
l = 1; % length - meter (m)
% Initial condition
theta_0 = [0;3];
% Time points
t_span = linspace(0,20,500);
% Solve ODE
[t, results] = ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0)
i = 1
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('time')
ylabel('plot')
for i = l:length(t)
x = (sin(results(i,1)))
y = (-cos(results(i,1)))
figure(2)
plot([0, x],[0, y],'-o')
axis ([-1 1 -2 0])
text(0, -1.6, ['time', num2str(t(i,1))])
M(i) = getframe(gcf);
pause(0.1)
end