Week 3 - Solving second order ODEs
AIM :- To simulate the behaviour of simple pendulum and to animated using MATLAB
THEORY :- In this program I have saw the moment of the simple pendulum. I now that the mass is applyed on the pendulm and the force is applied then the pendulum is movie in the sphere shape.
So using the MATLAB i have calculate the value of the displacement and veocity of the pendulum with respect the time.
I now that the mass is applied on the pendulum is downword side so gravity is also appled on the pendulum ball. Because the gravity is applied then the sfter some time pendulum is stop on the initial position. The force is applied so damping is start and damping is involved in this condition.
The moment of the pendulum in spare shape is called the oscillation. after some time oscillation come to rest and equilibrium position.
The initial position of the pendulum is 0 means the displacement is 0 no moment.
using the secound order differential equation this all problem is solve.
After the graph is plot i have see the displacement graph is similar to the sin graph and velocity is similar to the cos graph.
I have attached the video and graph.
My Youtube Link:- https://youtu.be/zD8SqQO6n3o
Googe Drive Link:-https://drive.google.com/file/d/1ggfb7FqxU8S4GewaAthTdsvgeprQygbi/view?usp=sharing
Solve the 2 ODE
2ND ORDER DIFFERENTIAL EQUATION
d²θ/dt² + (b/m)dθ/dt + (g/l)sinθ = 0
Where :-
b = damping Coefficient = 0.05
m = mass = 1
g = gravity = 9.81
l = length = 1
θ = θ1
dθ/dt = dθ1/dt = θ2
d²θ/dt² = d²θ1/dt² = d/dt(dθ1/dt) = dθ2/dt
put these value in the differential equation
dθ2/dt + (b/m)θ2 + (g/l)sinθ1 = 0
dθ2/dt = -(b/m)θ2 - (g/l)sinθ1
So the 2nd order differential equiation is break into the single order differential eqution so using the matlab function command this equation is solve is very easily. The program and graph is attached.
PROGRAM:-
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1;
theta_0 = [0;3];
t_span = linspace(0,20,100);
[t,result] = ode45(@(t,theta) ode_challenges_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
xlabel('time')
ylabel('plot')
legend('displacement','velocity')
grid on
ct = 1;
for i=1:length(result)
THETA = result(i,1);
x0 = 0;
y0 = 0;
x1 = l*sin(THETA);
y1 = -l*cos(THETA);
figure(2)
plot(x1,y1,'o','markersize',20,'markerfacecolor','r')
hold on
plot([x0 x1],[y0 y1],'linewidth',3)
plot([-0.5 0.5],[0 0],'linewidth',5)
hold off
axis([-1.5 1.5 -2 0.5])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
movie(M)
Videofile = VideoWriter('pendulum.avi','uncompressed AVI');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
FUNCTION CODE
function [dtheta_dt] = ode_challenges_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