Project

Transient behaviour of a Simple Pendulum

Aim

Write a program to simulate the transient behavior of a simple pendulum and to create an animation of its motion.

Programming to simulate the transient behavior of the simple pendulum is dom=ne below using MATLAB.

%self second order ODE    
clear all
close all
clc

%Inputs
m=1    %Mass of ball in kg.
b=0.05 %Damping coefficient.
g=9.81 %Accelaration due to gravity in m/s^2.
l=1    %Length of pendulum in meter.

%Total time
t_span=linspace(0,20,200); %Tells how far the integration needs to be done.

%Initial setup
theta_0=[0;3]; %Initial displacement=0 & Initial velocity=3.

%Solving ODE
[t,results]=ode45(@(t,theta) ode_funck(t, theta, b,g,l,m),t_span,theta_0);

%Plotting
figure(1)
plot(t,results(:,:),\'linewidth\',3)
xlabel(\'Time\');
ylabel(\'Angular displacement & Angular velocity\');
legend(\'Angular displacement\',\'Angular velocity\');

figure(2)
ct=1;
for i= 1:length(t_span)
    
    x0=0;
    y0=0;
    x1=l*sin(results(i));
    y1=-l*cos(results(i));
    plot([-1 1],[0 0],\'linewidth\',13,\'color\',\'black\');
    line([x0 x1],[y0 y1],\'linewidth\',3,\'color\',\'r\');
    viscircles([x1,y1],0.05,\'edgecolor\',\'b\',\'linewidth\',7);
    axis([-2.3 2.3 -1.5 .3])
    
    M(ct)=getframe(gcf);
    ct=ct+1;
end

movie(M);
videofile=VideoWriter(\'self_second_order_ODE.avi\',\'uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Function programme.

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

theta1=theta(1)
theta2=theta(2)

dtheta1_dt= theta2;
dtheta2_dt= -b/m*(dtheta1_dt) - g/l*(sin(theta1));

[dtheta_dt]= [dtheta1_dt;dtheta2_dt];
end

Explanation of code

Step1: Start with clear all, close all and clc in order to get smooth results.

Step2: Give the numeric values of all inputs like mass of bob, damping coefficient, acceleration due gravity and length of pendulum.

Step3: Setup initial condition for displacement, velocity and give the value for total time.

Step4: Now solve for ODE with proper syntax and plot the solution of ode.

Step5: Use figure(2) for showing the animation.

Step6: Introduce for loop and calculate the values for x1 and y1. x0 and y0 are assumed to be zero.

Step6: Plot calculated points and use viscirlces with higher linewidth in order to get filled bob.

Step7: Use movie command to create the animation.

OUTPUT

\"\"

The variation of angular displacement and angular velocity w.r.t time is shown in the above figure.

The animation of the simple pendulum is shown above.

Results

1) In order to get desired results values of b,m,g or l may be adjusted accordingly.

2) Same can be described as the motion of spring mass and damper system.

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.