Project

program for pendulum dumping using octave

explanation of program in octave.
first off all defining all inputs like :b,g,m.l
then defining initial conditions of angular displacement & Velocity.
then defining time interval with linspace command
then witing seperate ode function for pendulum dumping
then ploting graph of all 3 separate figure
then creating the annimation in octave .
then creating the movie with the help of magic image software and command window.

ERRORS FACED DURING WRITING PROGRAM.
i faced error because i did not defined the parameters when i written the ode function .
further with the help of mehul sir i had completed it.

now code for writting pendulum ode function

function[dtheta_dt] = pendulum_func(theta,t,b,g,l,m)
  
  b = 0.05;

 g = 9.81;
 
 l = 1;

 m = 1;
  
  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

2. main program.

##writing program to simulate the transient behaviour of simple pendulum and to create an animation of its motion.
##commands for clearing the previous workshop,command window and closing all points.

clear all 
close all
clc

 %inputs 
 %Damping coefficient
 b = 0.05;
 %Gravety in m/s^2
 g = 9.81;
 %length of the string in m 
 l = 1;
 %Mass in kg
 m = 1;
 
 %initial condition of velocity and time
  theta_0 = [0;3];
  
  %time point
  t_span = linspace(0,10,55);
  
  %solveing ODE and calling the4 function ode_func
  [results] =lsode(\'pendulum_func\',theta_0,t_span);
  
  %plotting figure
  
 subplot(5,4,[13,14,17,18]);
  plot(results(:,1),\'color\',\'b\');
  hold on

 
  plot(results(:,2),\'color\',\'r\');
  hold off
  
  subplot(5,4,[15,16,19,20]);
  plot(results(:,1),results(:,2));
  
  ylabel(\'positions\');
  xlabel(\'angular velosity\');
 
 ct=1;
 
 for i= 1:length(results(:,1))
      x0=0;
      y0=0;
      x1=1*sin(results(i,1));
      y1=-1*cos(results(i,1));
      
       subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
       plot([-1 1],[0 0],\'linewidth\',2,\'color\',\'b\');
       hold on 
        line([x0 x1],[y0 y1],\'linewidth\',2,\'color\',\'b\');
        hold on
        
        %ploting circle and mapping the centre to the string
        r=0.075;
        
        cir_deg = linspace(0,2*pi,1000);
        xc=r*cos(cir_deg);
        yc=r*sin(cir_deg);
        plot(x1+xc,y1+yc,\'linewidth\',2,\'color\',\'b\')
        hold off;
        
        %plotting bthe bob using maker and face color
        plot(x1,y1,\'-0\',\'markers\',20,\'markerfacecolor\',\'r\'); 
        
        r=0.6;%plot a curved rectangle and color its inner surface 
        rectangle(\'position\',[(x1-(r/2)),(y1-(r/2)),r,r],\'curvature\',[1 1],\'FaceColor\',\'r\',\'linewidth\',3)
        hold on
        axis equal
        
        grid on
        axis([-1.5 1.5 -1.5 0.5])
        pause(0.004);
        hold off
        
        Text = sprintf(\'pendulum%d.png\',ct);
        saveas(1,Text)
      
      ct=ct+1
     
  endfor

 

link for youtube video

https://youtu.be/CZWzGbZGoBw

3.screen shot of folder having images of different position of pendulum.

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.