Project

pendulum

Introduction:this project is to make the animation of the pendulum using differential equation and use the inbuilt ode solver in mat lab to solve the differential equation.

close all 
clear all 
clc
%pendulum motion
%constants
l=1 ;%length of the pendulum
m=1 ;%mass of the ball
b=0.05; %dampinfg factor
g=9.81; %accleration due to gravity
%intial condition
theta_0=[0;3];
%time span
t_span=linspace(0,20,200);
[result]=lsode('ode_func',theta_0,t_span);
theta=(result(:,1)+4.712);
x1=5;
y1=5;
plot(t_span,result(:,1))
hold on
plot(t_span,result(:,2))
 xlabel("time")
 ylabel("velocity and displacement")
  
ct=1;
for i=1:length(theta)
  y=sin(theta(i));  
  x=cos(theta(i));
  x2=x+x1;
  y2=y+y1;

 figure(ct)
         
         
        plot([x1 x2],[y1 y2],'linewidth',3,'color', 'b')
      plot(x2,y2,'marker','s')
       pause(0.3)
        file_text=sprintf('movements_of_pendulum%d.png',ct)
        saveas(gca, file_text);
         ct=ct+1;
end
       

this the main code which in which all the nessary parameters are give such as the

*initial condition

*time span

*all the constants

then passing the values to lsode inbuilt function which gives the solution of differential equAtion

then the function stores the values in the result

from that we can plot a graph like this

this graph explains how the the velocity and displacement changes with time span where xaxis is the time, and yaxis represent displacement and velocity of the intial given condition and constants .

the work converting the 2dimensional diffrential Eqation into a ode and then intergarting it is done by inbuilt lsode function and the esult value is stored to obtain velocity and displacement

%second order ode
function [dtheta_dt]=ode_func(theta_0,t_span)
  l=1 ;%length of the pendulum
  m=1 ;%mass of the ball
  b=0.05; %dampinfg factor
  g=9.81; %accleration due to gravity
 
 theta1=theta_0(1);
 theta2=theta_0(2);
 dtheta1_dt=theta2;
 dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
 [dtheta_dt]=[dtheta1_dt;dtheta2_dt];
 endfunction
 

*the errors that i faced iwast able to call the input constants as did in mat lab

https://youtu.be/DTlreXDuVGI link the video simulation

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.