Week 3 - Solving second order ODEs
Youtube link: https://youtu.be/5_eSd3UHuB4
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
function called for the program
clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=0.1;
%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);
figure(1)
plot (t,results(:,1))
hold on
plot (t,results(:,2))
ylabel("Plot")
xlabel('Time(sec)')
title('2nd order Derivative ')
% For loop for movie
ct=1;
for i =1:length(results(:,1))
x0=0
y0=0
x1= l*sin(results(i,1));
y1= -l*cos(results (i,1));
% plotting the animation
figure (2)
plot([-1 1], [0 0], 'linewidth', 5)
hold on
plot([x0 x1], [y0 y1], 'linewidth',3)
hold on
plot(x1,y1, 'o', 'markersize',20, 'markerFacecolor', 'c')
title('A Pendulum 2nd order Derivative ')
axis ([-1.5 1.5 -1.5 1])
pause (0.0000002)
hold off
M(ct)= getframe(gcf);
ct=ct+1;
end
movie(M)
videofile = VideoWriter('Pendulum.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
Program to be executed..

Graph plotted for pendulum motion,

Movie ploted

clear command,initial command,and then formula to solve with calling the function.
Code for ploting the graph.

For loop for the movie as the needed despc. and the specs for the movie and calling for the frames and saving it nd then execute it...

error found in line 10 : this was used instead of ; then the error was solved
there we conclude ODE is used to describe the transient behavior of a system.