Project

Program to Solve the Second Order ODE

Program:-


      clear all
      close all
      clc
      %Program to Solve second order ODE
    
      %Inputs
      %Damping Coefficient
      b=0.05;
      
      %Gravity
      g=9.81;
      
      %Length of Pendulum
      l=1;
      
      %Mass
      m=.1;
      
      %Initial Condition
      theta_0=[0;3];
      
      %Time Period
      t_span=[0 20]
      
      %Solving Second Order ODE
      [t,results]=ode45(@(t,theta)Matlab_ode_func(t,theta,b,g,l,m),t_span,theta_0);
                 
%                     axis([-1 1 -5 5])
      
       ct=1;
       for i=1:length(results(:,1))
           x0=0; 
           y0=0; 
  
                
             x1=l*sind(results(i,1))
             y1=l*-cosd(results(i,1))
           
%              line([-0.4 0.4],[0 0])
        

        figure(1)
        plot([x0 x1],[y0 y1],\'linewidth\',2,\'color\',\'g\')
        axis([-1 1 -1 1.5])
        M(ct)=getframe(gcf)
        ct=ct+1;
        
       end
        
       
        movie(M)
        videofile=VideoWriter(\'pendulum_motion.avi\',\'Uncompressed AVI\')
        open(videofile)
        writeVideo(videofile,M)
        close(videofile)
          hold on
                  line([-0.4 0.4],[0 0])  
        
            figure(2)
            hold on
          plot(t,results(:,1))
          plot (t,results(:,2))
          xlabel(\'Time\')
          ylabel(\'Plot\')
        

https://youtu.be/EiSSyvzou2Y

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.