Week 3 - Solving second order ODEs
https://drive.google.com/file/d/1DPnqwMfjyTMoR943W6gdkjGPGCRE36Ni/view?usp=sharing
SIMPLE PENDULUM :-
A heavy point mass suspended by a weightless, perfectly flexible and inextensible string, from a perfectly rigid support is called "SIMPLE PENDULUM".
The tension in the string depends both on mg and centripetal force muThe acceleration of the simple pendulum will be given by, a = - g sing
The time period of the simple pendulum is, T = 24W
The value of the theta (0) and the rate of theta (0) at which it is changing for a simple pendulum can be determined or solved by using the set of "ordinary differential equations".
? OIDINARY DIFFERENTIAL EQUATION (ODE) :-
An ordinary differential equation is an equation containing an unknown function of one real or complex variable x. The unknown function is generally represented by a variable which therefore depends on x.
The examples for the ode are,
dy
= F(r) dy
dr = F ( 2)
d'y
= F(y) de2
In engineering, ODE is used to describe the transient behaviour of a system. A example is a simple pendulum. The following is the second order ode of a simple pendulum. The way the pendulum moves depends on the newtons second law .
simple_pendulum.m
%step 1: input
%Damping Coefficient
b=0.02;
%gravity of earth
g=9.81;
%length of rope/string
l=1;
%mass of ball
m=0.1;
%step 2:Initial condition for displacement and angular velocity
theta_0 = [0;3];
%step 3: time interval points
t_span= linspace(0, 20, 500);
%step 4: ODE results
%call ode_fun function
%ode45 gives result in rad and rad/s.
[t,results]=ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
%step 5 plotting
%figure(1)
hold on
plot(t, results(:,1),'linewidth',3,'color','g')
plot(t, results(:,2),'linewidth',3,'color','r')
axis([0 20 -6 8])
title('For Simple Pendulum')
xlabel('Time in sec')
ylabel('Angular Velocity(rad/s) / Displacement(rad)')
legend('Displacement', 'Angular velocity')
%step 6: animation of pendulum
amplitude= results(:,1);%store amplitude values in separate matrix for loop
p=1;
for i=1:length (amplitude)
angle=amplitude(i);
figure(2)
title('Simple Pendulum')
%fix point of pendulum
x0 = 0;
y0 = 0;
%another end of pendulum/cordinate of mass ball
x1= l*sin(angle);
y1= -l*cos(angle);
%plot
plot([-1.1 1.1], [0 0], 'Linewidth', 2);
hold on
plot([x0 x1],[y0 y1], 'color', 'g', 'linewidth', 2)% string
plot(x1, y1, 'o', 'markers',20, 'markerfacecolor', [1 1 0])%mass ball
hold off %removing previous position
grid on
axis ([-1.5 1.5 -1.5 0.5])
pause (0.001)
M(p)= getframe(gcf);
p = p+1;
end
%making movie
movie (M)
videofile = VideoWriter('simple_pendulum.avi', 'uncompressed avi');
open(videofile)
writeVideo(videofile, M)
close(videofile)
odefuntion.m
function[dtheta_dt] = ode_fcn(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
explanation: