Project

MOTION OF PENDULUM

the errors which i faced in this pendulum program were:-

1. while doing a movie it wasnt animating so i had to change parameters and put some limits on that so the animation moves

2. the value of y is not changing much so either i have to change the length of the string or theta values in it but on doing that i dont get a good graph

\"\"

the youtube link for this is:-

https://youtu.be/zzWIzWZcOVc

%solving transient response of pendulum
clear all
clc

%inputs
b=0.05
g=9.81
l=1
m=1
ct=1

%initial condition 0 displacement and initial velocity is 3
theta_0=[0;3];
%time span
t_span=linspace(0,10,500);

%solving ODE
[t,sol]= ode45(@(t,theta) ode_func(t,theta,b,g,l,m), t_span, theta_0);

%plot of theta and velocity with time
figure(1)
subplot(2,1,1),plot(t,sol(:,1))
xlabel(\'time\')
ylabel(\'displacement angular\')
title(\'plot : angular displacement vs time\')
hold on
subplot(2,1,2),plot(t,sol(:,2),\'color\',\'r\')
xlabel(\'time\')
ylabel(\'angular velocity\')
title(\'plot : angular velocity vs time\')

%animation
theta=sol(:,1)
ct=1
for i=1:length(theta)
     THETA=theta(i)
     x0=0
     y0=0
     x1=l*sind(THETA)
     y1=-l*cosd(THETA)
     
     figure(2)
     plot([x0 x1],[y0 y1],\'linewidth\',1,\'color\',\'b\')
     hold on
     plot(x1,y1,\'marker\',\'O\',\'MarkerSize\',10,\'color\',\'g\',\'MarkerFaceColor\',\'r\')
     
     title(\'animation\')
     hold off
     axis ([-0.05 0.05 -1.5 1.2])
     pause(0.00003)
     M_pend(ct)=getframe(gcf);
     ct=ct+1
end
movie(M_pend)
videofile= VideoWriter(\'motion_of_pendulum.avi\',\'uncompressed avi\')
open(videofile)
writeVideo(videofile,M_pend)
close



% function
function [theta_dot]=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));
theta_dot=[dtheta1_dt;dtheta2_dt];
end
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.