simple pendulum using matlab

 ORDERLY DEFFRENTIAL EQUATION:

In applied engineering and science many physical initial and boundary value problems can be described by ODE.

The behavior of many physical problem,particularly those system undergoing time dependent changes can be formulated as ODE.

The diff.equ involves one or more physical quantities such as displacement,velocity,temperature etc..

An nth order ODE may be represented as F(x,y,y’,y’’…)=0

SIMPLE PENDULUM:



A simple pendulum is a mechanical device,the thin string or massless string is fixed in a supported beam and the other end is fixed to a bob.actually,its act like a newton’s 2nd law,we give a force to the bob,the pendulum swig due to net force and mass.according to the net force and mass , the bob travels high or low.

THE EQU OF A SIMPLE PENDULUM:

b-damping co-efficient

m-mass of the object

g-gravity

l-length og the string

 

First of all,we change the 2nd order ODE to 1ST order ODE

 According to this formulla,create a function in matlab:

function [dtheta_dt]=ode_func(t,theta,b,m,l,g)

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

THEN,WRITE A ODE PROGRAM TO FIND A DISPLACEMENT & VELOCITY AS WELL AS ANIMATION OF SIMPLE PENDULUM

clear all
close all
clc

%inputs
b=0.05;
m=1;
l=1;
g=9.81;

%initial condition
theta_0=[0;5];

%time points
t_span=linspace(0,10,500);
%solve ode
ct=1

%calling a function
[t,results]=ode45(@(t,theta)ode_func(t,theta,b,m,l,g),t_span,theta_0);

figure(1)
%plotting displacement w.r.t time
plot(t,results(:,1))
hold on
%plotting velocity w.r.t time
plot(t,results(:,2))

xlabel('time')
ylabel('plot')
%simple pendulum animation
for i=1:length(results(:,1))
theta=results(i,1);
x0=0;
y0=0;
x1=x0+l*sin(theta)
y1=y0-l*cos(theta)

figure(2)
plot([-1 1],[0 0],'LineWidth',3)
hold on
plot([x0 x1],[y0 y1],'LineWidth',2)
plot(x1,y1,'Marker','o','MarkerFaceColor','b','LineWidth',10)
axis([-1.5 1.5 -1.5 1.5])
hold off 
%create a animation
M(i)=getframe(gcf);
end
movie(M)
videofile = VideoWriter('ode.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
   

THROUGH THIS PROGRAM AVI FILE SAVE AUTOMATICALLY,WHILE RUN THE PROGRAM

 google drive link

https://drive.google.com/file/d/1igm5U2or2Eum-ZcOu8gjroUqop-5Wqsq/view?usp=sharing

error faced while creating this program

when i run the program the animation comes like this and then i put hold off command at the end figure 2.afterwards its animated like a pendulum...

Comments

Popular posts from this blog

DRAG FORCE

2r robotic arm