Week 3 - Solving second order ODEs
https://drive.google.com/drive/folders/1qtrR6Hlm6w4mEkhBLrW1Q5ttNhJMuytF?usp=sharing
AIM :
To solve an ordinary differential equation(ODE) and use the calculation infoemation to animate the motion of the pendulum via Matlab.
INTRODUCTION:
Pendulums has many applications and were utilized often before the digital age. They are used in clock mentronomes due to the regulation of their period, in wrecking balls and playground swings,due to their simple way of buliding up and keeping energy.
An ordinary differential equation (ODE) is a differential equation containing one or more function of one independent varialble and the derivation of those function.

let theta = theta1 displacement
dtheta/dt=dtheta1//dt=theta2 angular velocity
dtheta2/dt=-bm/*theta2+g/l*sin(theta1)=a
therefore' theta_dot=[theta2;a]
Code Explanation:
The function code
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
The main program
clear all
close all
clc
%inputs
b= 0.05;
g= 9.81;
l= 1;
m= 1;
% initial conditions
theta_0= [0;3];
%timme 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);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
title('damped harmonic motion of a pendulum')
legend('Angular displacement','Angular velocity')
ylabel('plot')
xlabel('time(seconds)')
fig= 1;
for i = 1:length(t)
%intial position of the pendulum
x0= 0;
y0= 0;
%finel positon
x1 = l*sin(results(i,1));
y1 = -1*cos(results(i,1));
%plotting
figure(2)
%base line
plot([-1,1],[0,0],'linewidth',4,'color','y');
% pendulum line
line([x0 x1],[y0 y1],'linewidth',3,'color','r');
hold on;
%pendulum ball
plot(x1,y1,'o','markersize',30,'markerfacecolor','b');
grid on
axis([-2 2 -2 1]);
pause(0.01);
hold off
M(fig) = getframe(gcf)
fig= fig+1;
end
% for genarating and storing the video file in avi from at
movie(M)
videofile = VideoWriter('second_order_ODEs.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Error Occurred
In the funtion i typed theta_o instead of theta_2 in line 6
plot(x1,y1,'o','markersize',30,'markerfacecolor','b'); i typled maekersize instead of 'markersize'
spelling of "compressed" was typed as "comresssed"
All the errors are rectified by my guide.