Week 3 - Solving second order ODEs
https://youtu.be/m32FtfMAJM4- Youtube link for video
clear all
close all
clc
% Input of variables
b=0.05;
g=9.81;
l=1;
m=1;
% Initial condition
theta_0 = [0;3]; % Initial angular displacement and Andgular velocity
% Time points
t_span = linspace(0,10,20);
% To solve ODE
[t, results] = ode45(@(t, theta) ode_func(t, theta, b,g,l,m), t_span, theta_0);
% To defined pivot point of pendulum and plot it.
x0=0;
y0=0;
plot(x0, y0,'marker', 'o')
% To extract the first column of a result and assigned it to 'y'
y = results(:,1); % Theta/Angular displacement
% To create images for each time value and stored it in array ‘M’.
ct=1;
for i=1:length(t_span) % i=1,2,3,4,5,,,,,,20
x1 = l*sin(y(i));
y1= -l*cos(y(i));
plot([x0 x1],[y0 y1],'linewidth',3,'marker','o')
hold on
plot(x1, y1, 'marker','o', 'color','g','markersize',30, 'markerfacecolor', 'g')
hold off
title({'Simple harmonic motion'; 'of a pendulum'}, 'color','r')
axis([-1 1 -2 0])
pause(0.01)
M(ct)= getframe(gcf);
ct=ct+1;
end
% To create animation of S.H.M. of simple pendulum
movie(M)
videofile = VideoWriter('pendulum.avi', 'Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Error faced During Programming


