Week 3 - Solving second order ODEs
Second order differential equation
In ODE equation, The rate of angle changes with respect to time.The pendulum describes the motion of mass and damper.
Derived ODE equation

θ=θ1
dθ/dt=dθ1/dt=θ2 (equation 1)
d^2θ/dt^2=d^2θ1/dt^2=d/dt(dθ1/dt)=dθ2/dt (equation 2)
Pendulum equation,
(d^2θ/dt^2)+(b/m)(dθ/dt)+(g/l)sinθ=0
(d^2θ1/dt^2)+(b/m)(dθ1/dt)+(g/l)sinθ1=0
replace equation 2 and 1,
dθ2/dt+(b/m)θ2 +(g/l)sinθ1=0
in this problem we use function to solve,
refer the code for more details,
b=0.05;
g=9.81;
l=1;
m=1;
theta_0=[0;5];
t_span=linspace(0,20,500);
[t,results]=ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('plot')
function[dtheta_dt]=ode_func(t,theta,b,g,l,m)
theta1=theta(1)
theta2=theta(2)
dtheta1_dt=theta2;
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end