Project

simulate the transient behaviour of a simple pendulum and created an animation of it s motion using matlab

AIM:Write a program to simulate the transient behaviour of a

simple pendulum and to create an animation of it\'s motion

ation of it\'s motion.

theory:

formula used:

In the above equation,

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

Write a program in Matlab\\Octave that will simulate the pendulum motion, just like the one shown in the start of this challenge.

use,

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s2.

Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.

FUNCTION CODE

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/l)*sin(theta1);
dtheta_dt=[dtheta1_dt; dtheta2_dt];
end

MAIN PROGRAM

clear all
close all
clc
b=0.06;
g=9.81;
l=1;
m=0.1;
%initial condition
theta_0=[0;5];
%time points
t_span=linspace(0,10,500)
%solve ode
[t,results]= ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span, theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel(\'plot\')
xlabel(\'time\')
theta=results(:,1);
c=1;
for i=1:length(theta)
    Theta=theta(i);
    %initial point
    x0=0;
    y0=0;
    %movement of pendulum
    x1=1*sin(Theta);
    y1=-1*cos(Theta);
    figure(2);
    %plotting string
    plot([x0 x1],[y0 y1],\'color\',\'r\');
    hold on
    %plotting pendulum bob
   plot(x0,y0,\'o\',\'markersize\',10,\'MarkerFaceColor\',\'y\');
   plot(x1,y1,\'o\',\'markersize\',50,\'MarkerFaceColor\',\'y\');
   hold off
    axis([-1 1 -1.5 1]);
    pause(0.03);
%     hold off
    M(c)=getframe(gcf);
    c=c+1;
end
% %creating movie
movie(M)
Videofile = VideoWriter(\'pendulum.avi\',\'Uncompressed AVI\');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)

output 1:graf

\"\"

output 2:pendulum animation movie

error faced:

*in for loop function i have didnt type caps Theta for that i have type theta so that i have get error i cant able to find for 1 hrs after that i have gone through all the code then i found the error

conclusion:

.\'. i have done plotted in the graf to find how the daming occur for each value using code and i have done pendulum animation movie video for the above code

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.