Week 3 - Solving second order ODEs
AIM: to find the solution of the second order ODE and Find the position of Pendulum as a time function.
THEORY:
1.The Simple Pendulum A simple pendulum consists of a mass m (of negligible size) suspended by a string or rod of length L (and negligible mass). The angle it makes with the vertical varies with time as a sine or cosine.
2.The Simple Pendulum Looking at the forces on the pendulum bob, we see that the restoring force is proportional to sinθ, whereas the restoring force for a spring is proportional to the displacement (which is θ in this case).
3.The Simple Pendulum Substituting θ for sin θ allows us to treat the pendulum in a mathematically identical way to the mass on a spring. Therefore, we find that the period of a pendulum depends only on the length of the string:
THE ODE is given as
1.We First convert the 2nd order ODE into the two first order differential equation.
2.PROGRAM:
close all
clear all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
% initial condition
theta_0 = [0;3];
% time points
t_span = linspace(0,20,500);
% solve ode45
[t,results] = ode45(@(t,theta)lsode_func(t,theta,b,g,l,m),t_span,theta_0);
subplot(5,4,[13,14,17,18])
plot(t,results(:,1),'color','b');
hold on
plot(t,results(:,2),'color','r');
hold off
subplot(5,4,[15,16,19,20])
plot(results(:,1),results(:,2))
xlabel('position radiance');
ylabel('angular velocity');
ct = 1
for i = 1:length(results(:,1))
x0 = 0
y0 = 0
x1 = 1*sin(results(i,1));
y1 = -1*cos(results(i,1));
subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12])
plot([-1 1], [0 0],'linewidth',4,'color','r')
hold on;
plot([x0 x1], [y0 y1],'linewidth',2,'color','b')
hold on;
% r = 0.075
% cir_deg = linspace(0,2*pi,1000);
% xc = r*cos(cir_deg);
% yc = r*sin(cir_deg);
% plot(x1+xc,y1+yc,'linewidth',3)
% hold off
plot(x1,y1,'-o','markersize',20,'markerfacecolor','r');
% r = 0.25
% rectangle('position',[x1-(r/2),y1-(r/2),r,r],'curvature',[1 1],'facecolor','r','linewidth',3)
% hold on
% axis equal
grid on
axis([-1.5 1.5 -1.5 0.5]);
pause([0.003]);
hold off
## q(ct) = getframe(gcf);
text = sprintf("pendulum%d.png",ct);
saveas(1,text);
ct = ct+1;
end
Explanation:
1.We give all the input of simple pendulum which need us for calculation i.e. b ,g, l,m.
2.We give initial condition of simple pendulum ie.Theta_0 value in which we give initial value of theta as '0' and initial velocity as 3 m/s.
3.after that we give Time Span value of 20 sec in which we use there linspace commamnd of 500 elements.
4.Then we used ODE45 solver to solve ODE .there are we use function as "lsode_func" to solve the given differential equation into two first order equation.
5.Then we use plot command to plot graph.
6.after that for pendulum position we use "FOR" loop to have all plots of pendulum with the time as a function .
7.we use "ct" for each new iteration.
8.after that we use markersize command to draw pendulum bob.
9.after getting all plots use syntax to save animation in octave soft.
ERRORS FACED:
1.when I written a program i used "markers" without "markersize" and it gives error as
2.in the "FOR" loop i do not used right syntax because of that program runs it never shows error but but it give only one iteration plot
CONCLUSION: we plot simple pendulum plots with the function of time and also solved the ODE .
ANIMATION LINK: https://drive.google.com/file/d/1h9PLi46Z5W4drm5Ib58d_0H0NBYxz8Ru/view?usp=sharing