Project

To solve the equation of motion of a simple pendulum with damping

Aim :-

To solve the equation of motion of a simple pendulum with damping

Given Equation :-

`(d^2 θ)/(dt^2 )+ b/m dθ/dt+ g/l sin⁡〖θ=0〗`

Governing Equation :-

1. `(dθ_1)/dt=dθ_2`

2. `(dθ_2)/dt= -(b/m 〖)θ〗_2-(g/l 〖)sin〗⁡〖θ_1 〗`

Objective :-

  1. To calculate the displacement with respect to time
  2. To generate a plot of time vs displacement and velocity

Content Body :-

function [dtheta_dt] = ode_func(t,theta,b,g,l,m)
     theta1 = theta(1)
     theta2 = theta(2)
     
     dtheta1_dt = theta2;
     dtheta2_dt = -(b/m)*theta2 - (g/1)*sin(theta1);
     dtheta_dt = [dtheta1_dt;dtheta2_dt];



end
clear all
close all
clc

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

 
%Initial condition

theta_1=[0;3]
%time points
 t_span=linspace(0,20,500);

%solve ODE
[t, solution] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_1);

    figure(1)
    plot(t,solution(:,1))
    hold on
    plot(t,solution(:,2))
    xlabel('time')
    ylabel('plot')
    title('variation of angular displacement and velocity w.r.t time','color','r')
    


 theta_1 = solution(:,1)
 ct=1
for i = 1:length(theta_1);
    theta_2 = theta_1(i);
    
    x0 = 0;
    y0 = 0;
    
    x1 = l*sin(theta_2);
    y1 = -l*cos(theta_2);
    
    %plotting pendulum
    figure(2)
    plot([-0.8 0.8],[0 0],'color','r','linewidth',5)
    hold on
    plot([x0 x1],[y0 y1],'color','b','linewidth',3)
    hold on
    plot(x1,y1,'o','markers',25,'markerfacecolor','y')
    hold off
    axis([-1 1 -2 1])
    grid on
    
    M(ct)=getframe(gcf)
    ct=ct+1
    
end

movie(M)
videofile = VideoWriter('pendulum displacement.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
  1. We have been given the below points

M= 1kg ; mass

G = 9.81 m/s2 ; gravity

L = 1 m ; length of string

B = 0.05 ; damping coefficient

  1. We have marked initial displacement as 0 with velocity as 3 rad/s. And we will calculate the the displacement and velocity for 20 sec.
  2. We will use ode45 function to calculate the pendulum motion
  3. In this case, ode45 (order differential equation) is the function of time and theta
  4. To generate the animation, we will take length of theta from the output which be got from ode45 function
  5. And then with the help of for loop we will trace each and every position of pendulum.

Conclusion :-

Hence we have plotted the displacement and velocity w.r.t time.

Youtube link :-

https://youtu.be/laK5pw54Qr8

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.