Week 3 - Solving second order ODEs
clear all;
close all;
clc
%inputs
b=0.05;
g=9.81;
l=1;
m=1;
theta_0=[0;3];
t_span=linspace(0,20,200);
[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,result(:,1),'linewidth',1,'color','r');
xlabel('Angular Displacement in Radians');
ylabel('Time in seconds');
title('Angular Displacement vs Time');
hold off
ct=1;
A=(results(:,1));
for i=1:length(A);
A1=results(i,1);
X0=0;
Y0=0;
Y1=-1*cosd(A1);
X1=1*sind(A1);
plot([X0 X1],[Y0 Y1],'linewidth',7)
hold on
plot(X1,Y1,'o','markersize',15,'markerfacecolor','g');
plot([-0.2 0.2],[0 0],'linewidth',6)
axis([-0.5 1.0 -1.5 0]);
title('Ode_pendulum')
legend('connecting rod','mass','fixed position');
xlabel('X-axis')
ylabel('Y-axis')
hold off
M(ct)=getframe(gcf);
ct=ct+1;
end
movie(M)
videofile=VideoWriter('ode_simple_pendulum.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
This is the Matlab code Main program.
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
This is the Matlab Program Ode_func. Program

This figure represents the angular displacement vs Time.

I got an error on this step I put this as ode_function and I forgot to represent as ode_func in my system so it got corrupted. after I resolve it now it runs fine.
I will include the animation of the pendulum on this google drive link:
https://drive.google.com/file/d/1WdeoiQL8ta7nFfzXo19X54PcrU1pLnpV/view?usp=sharing
and I also include screenshot

Conclusion:
Each frame of the swing of the basic pendulum is captured and stitched together to generate an animated video clip. There's a direct link to the video file here.