Project

Visualize the pendulum motion including the parameters at each pt....

Aim:-

To see the motion of pendulum and also the parameters related to it such as velocity and displacement at each pt. of its motion.

Background:-

A pendulum is mechanism consist of a weight suspended on a string and is pivoted at the other end so that it can oscillate freely when displaced.

Image credits: Britannica,Inc.

Calculations:-

1) From newton secound law we can describe the motion of the pecdulum in the form a secound oreder diffrential equation.

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

2) To write this secound order differential equation, we break it into two single order diffrential equation for ease:

a) d`theta`/dt= `theta`2

b) d`theta`2/dt= [-b*`theta`2/m]-[g*sin(`theta`1)/L]

Here we have:-

1) L=length of string (meters)

2) b= dammping coefficient

3) m= mass of bob (kg)

4) g= accelaration due to gravity (m/sec^2)

5) t= time (sec)

6) `theta`=angle made w.r.t stationary (radian)

3) The equations are written in matrix form in matlab for ease of solving:-

d/dt[`theta`2 ; `theta`1]= [`theta`2 ; -b*`theta`2/m]-[g*sin(`theta`1)/L ]

4) While programing function 'motion_of_pendulum_fun' is created and linked to main program for easier program understanding to matlab. The function is linked to ode45 function of matlab which in our case is used to calculate the different values of displacement and velocity w.r.t time.

Assumptions:-

1) The inputs taken are:

a) L=1 meter

b) m= 1 kg

c) b= 0.05

d) g=9.81 m/sec^2

e) simulation time= 0-20 sec

f) velocity at t(0)= 3 rad/sec

g) `theta` at t(0)= 0 rad.

Program:-

--> main program..

% Program to visualize the kinematic motion of pendulum
% Also to see the change in velovity and displacement respectively

%Inputs
b=0.05;                                    %damping coefficient
m=1;                                       %mass in kg
g=9.81;                                    %gravitational accelaration in m/sec^2
L=1;                                       %length in meters

%initial conditions
theta_initial=[0;3];                       %initial values of [displacement velovity]

%no. of time points
time_range=linspace(0,20,400);             %time pts. between 0-20 sec (here 400)

%ODE of simple pendulum
%Using the ode45 inbuilt matlab solver
[time, result]=ode45(@(t, theta) motion_of_pendulum_fun(t,theta,b,m,g,L), time_range,theta_initial);

%ploting the graph
b=1;                                           %variable to measure frame number
for i=1:399                                    %loop to get frames
figure(1)                                      %creats new figure naming(1)
subplot(2,1,1)                                 %creats a plot of given size in figure
plot(time(i:i+1,1),result(i:i+1,2),'r')        %plots the time to velocity line
hold on                                        %takes next argument in same plot
plot(time(i:i+1,1), result(i:i+1,1),'g')       %plots the time to displacement line
xlabel('time->')                               %gives x-axis label
ylabel('values->')                             %gives y-axis label
axis([0 21 -3.5 3.5])                          %sets the axis limit
grid on                                        %turns on grid of plot
angle_theta=(result(:,1));                     %hold value of angles ,(L=1) not divided
x_co=-1*(sin(angle_theta));                    %hold x co-ordinates of pts. of pendulum
y_co=-1*(cos(angle_theta));                    %hold y co-ordinates of pts. of pendulum
subplot(2,1,2)                                 %creats secound subplot in same figure
plot(x_co(i,1),y_co(i,1),'O--k');              %plots the string
hold on                                        %holds for next argument in same plot
plot([0 x_co(i,1)],[0 y_co(i,1)]);             %plots the bob
hold off                                       %releases the hold
axis([-1 1 -1.2 0]);                           %sets axis limit
grid on                                        %turns grid on
Frame(b)=getframe(gcf);                        %captures each frame into variable frame
b=b+1;                                         %increments to set value to next frame
end                                            %terminates the for loop

%Saving the frames into a clip
videofile=VideoWriter('pendulum_motion.avi','Uncompressed AVI')   %creats video file
open(videofile)                                                   %open video file
writeVideo(videofile,Frame)                                       %write the frames
close(videofile)                                                  %close video file

--> function linked to the main program

%function to give the values of displacement and velocity w.r.t time

function [theta_val]=motion_of_pendulum_fun(t,theta,b,m,g,L)   %creats a function
theta1=theta(1);                                               %assigns value to theta1
theta2=theta(2);                                               %assigns value to theta2
theta1_dt=theta2;                                              %first 1st order equation
theta2_dt=-1.*(((b*theta2)/m)+((g.*sin(theta1))/L));           %secound, 1st order eqn.
theta_val=[theta1_dt                                           %assign value to theta_val
    theta2_dt];
end                                                            %terminates the function

Outputs:-

1) graph of change of velocity and displacement w.r.t time

red line indicates velocity in (rad/sec)

green line indicates displavement in (rad)

2) motion of the pendilum

3) We can see the created animation to get a proper idea of motion of pendulum, displacement of bob, and its velocity w.r.t time.

pendulum_motion

Conclusion:-

We saw how the secound order deffrential equation can be easily solved in matlab and can visualize the results fairly easily.

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.