Week 3 - Solving second order ODEs
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
theta_0 = [0;3]
%initial condition
%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);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
figure(2)
plot(results(:,1),results(:,2))
xlabel('position-rad')
ylabel('angular velocity rad/sec')
v = results(:,1)
ct = 1
for i = 1:length(results)
x0 = 0
y0 = 0
x1 = l*sin(results(i));
y1 = -l*cos(results(i));
figure(3)
plot([-2 2],[0 0],'linewidth',3)
hold on
plot([x0,x1],[y0,y1],'linewidth',3)
hold on
plot(x1,y1,'marker','.','markerFacecolor','r','markersize',40)
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);
This programe is how to animation the simple pendulum motion in time during the tmie of 0 to 20 sec.
the initial conditions are
angular displacement is : 0
angular velocity is : 3rad/sec
time = 0
THIS function is to slove the seconde oder of eqution
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
after the same programe the result will be form has the to coloums one for the displacement and other one is foe the velocity.that two valves will give the motion of the simple pendulum we need to take the valve of the displacement form the coloum 1 iin resultsthat will be showing motion of the simple pendulum.
The all o coloum valves are showing has the theta valves we need sub in theta .


file:///C:/Users/ravin/Videos/pendulum.avi