Project

Pendulum motion

AIM:

To write a program in MATLAB/OCTAVE to describe transient behaviour of a simple pendulum and create an animation of it.

THEORY:

Ordinary Differential Equations(ODE) are a set of equations which can explain the motion of many mechanical systems which include springs and dampers.

This project aims at solving an ODE for a simple pendulum as a function of time considering the air damping and its stiffness.

The ODE that governs the transient motion of a simple pendulum is given below:

(d^2(theta)/dt^2) + (b/m)*(d(theta)/dt) +

(g/L)*sin(theta) = 0

This equation is in accordance with Newtons second law of motion.

The first term in the equation stands for inertia of the system and opposes the system motion.

The second term represents force due to damping and acts opposite to direction of motion.

The third term represents the component of system weight that acts in opposite direction to the system motion.

Program for MATLAB/OCTAVE:

The project is broken down into two parts and the same is explained as follows:

1.)First, we have to write a program to solve the given ODE:

function Dtheta = pendulum_motion_ode(theta,t)
%inputs
b = 0.5;
l = 1;
m = 1;
g = 9.81;
theta1 = theta(1);
theta2 = theta(2);
Dtheta(1) = theta(2);
Dtheta(2) = -(b/m)*theta(2) - (g/l)*sin(theta(1));
Dtheta = [Dtheta(1);Dtheta(2)];
end

2.) Then, we will write a program to simulate the pendulum motion according to the given ODE:

clear all
close all
clc



%initial conditions
theta_0 = [0;3];

%duration
t_span = linspace(0,20,200);
l = 1;

%solving the ode
[results] = lsode(\'pendulum_motion_ode\',theta_0,t_span)



%plotting
plot(t_span,results(:,1))
hold on
plot(t_span,results(:,2))
xlabel(\'time\')
ylabel(\'amplitude\')
hold off
figure(2)
plot(results(:,1),results(:,2))
xlabel(\'angular displacement\')
ylabel(\'angular velocity\')

ct=1;
for i = 1:length(results(:,1))
  position = results(i,1);
  
  x0 = 0;
  y0 = 0;
  
  x1 = l*cos(position-(pi/2));
  y1 = -l*sin(position+(pi/2));
  
  figure(3)
  plot([x0,x1],[y0,y1],\'linewidth\',3)
  hold on
  plot(x1,y1,\'marker\',\'.\',\'markersize\',40) 
  plot([-1,1],[0,0],\'linewidth\',4,\'k\')
  hold off
  axis([-3,3,-3,3])
  grid on
  pause(0.1)
 

  ct = ct + 1;
  end

Stepwise explaination of the above codes:

1.) In the first code, a function for solving the given ODE is written with variables there and t(time).

2.) Constants of the equation which are coefficient of damping(b), acceleration due to gravity (g), Length of string (L) and mass of the Bob(m) are defined.

3.) Then the second order differential equation is converted into first order differential equation as shown in the code.

4.) In the second part, the initial conditions for angular displacement and angular velocity are input as given in the question. Also the duration for which the simulation has to take place is also specified

(20 seconds).

5.) Using the \"lsode\" function, the first code which was written to store the variables the differential equations and will be called and will be solved using the initial conditions for the given duration.

The solution will be stored in results vector.

6.) Next step is to plot angular displacement and angular velocity versus time.

7.) Using the for loop, the result of each loop is generated and saved using the sprintf and saveas function. The Bob at the end of the string is created using the marker function.

8.) Finally, all the saved images are stitched together create the required animation using imagemagick.

RESULT:

1.)Plot of angular displacement and angular velocity versus time.

\"\"

2.)Plot of angular displacement versus angular velocity.

\"\"

ANIMATION:

The animation has been submitted as an attachment below.

The pendulum moves according to the given ODE.

ERRORS:

I had to face some errors due to some typos which were later rectified.

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.