Project

solving simple pendulum second order ODE in MATLAB

AIM:-

1.calculate the angular displacement and angular velocity of simple pendulum using MATLAB ODE fucntion.

2.make the animation of the simple pendulum oscilation.

OBJECTIVES:-

this rpoject is about the how to calculate the simple harmonic motion in simple pendulum using MATLAB and how to make the animation.in this MATLAB code ODE function has been used to solve the problem.

CALCULATIONS:-

L=length of connecting thread or rod in m

M=mass of the bob in Kg

b=damping coefficient `(Kgm-s)/(rad)`

g=gravity `m/s^2`

t=time in s

initial displacement = 0 rad

initial velocity = 3 `(rad)/s`

ordinary differential equation for simple pendulum is

`(d^2theta)/(dt^2)+b/m(d theta)/dt+g/l sin theta=0`

consider `theta=theta_1`

then

`(d^2theta_1)/(dt^2)+b/m(d theta_1)/dt+g/l sin theta_1=0`

conside `(d theta_1)/dt=theta_2`-------------1

then

`(d theta_2)/(dt)=-b/mtheta_2-g/l sin theta_1`----------2

by writing the equation 1 and 2 in matrix form

`d/(dt)[theta_1; theta_2]=[theta_2 ;-b/mtheta_2-g/l sin theta_1]`

MATLAB PRORAM:-

FALLOWED STEPS

1.collected inputs

2.assign the inputs to MATLAB.

3.programmed ode45 and required functions.

4.plotted the graph between angular disp, angular velocity vs time.

5.make the animation program.

clear all;
close all;
clc
%inputs for pendulum
b=0.05;
g=9.81;
l=1;
m=1;
theta_0=[0;3];
t_span=linspace(0,20,200);
[t,results]=ode45(@(t,theta) ode_function(t,theta,b,g,l,m),t_span,theta_0);
% making a plot of angular disp , angular velocity vs time
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('time ')
ylabel('plots')
legend('displacement','velocity');
hold off
ct=1;
B=(results(:,1));
%getting the results for animation
for i=1:length(B);
    B1=results(i,1);
    X0=0;
    Y0=0;
    Y1=-1*cosd(B1);
    X1=1*sind(B1);
    plot([X0 X1],[Y0 Y1],'linewidth',5)
    hold on
    plot(X1,Y1,'o','markersize',20,'markerfacecolor','r');
    plot([-0.2 0.2],[0 0],'linewidth',7)
    axis([-0.6 1.2 -1.5 0.1]);
  
   title('OSCILATION OF SIMPLE PENDULUM')
   legend('connecting tread(rod)','mass','fixed position');
   xlabel('X-axis')
   ylabel('Y-axis')
   hold off
 %code for making movie.
     M(ct)=getframe(gcf);
       ct=ct+1;
end
%Movie making code
 movie(M)
 videofile=VideoWriter('simple_pendulum.avi','Uncompressed AVI');
 open(videofile);
 writeVideo(videofile,M);
 close(videofile);
 

ode_function program for above program

function [dtheta_dt]= ode_function(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

RESULTS:-

figure of angular disp,velocity vs time

ANIMATION VIDEO:-

ERRORS:-

STEPS FALLOWED TO SOLVE RESULTS:-

1. took the help from MATLAB help.

2.check in google.

3.check youtube videos.

4.rewatching the course videos.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.