Project

Solving the 2nd order differential equation through ode function in matlab

b=damping coefficient

m=mass

g=gravity

l=length

This equation is 2nd order differential equation in which harmonic motion can be calculated and the best example of it is PENDULUM.

Here we have the procedure of getting a harmonic motion of a pendulum in MATLAB.

MATLAB FUNCTION CODE:

function [dtheta_dt]=ode_func(t,theta,b,g,l,m)
theta1 = theta(1);
theta2 = theta(2);
dtheta1_dt= theta(2);
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end

CODE TO SOLVE THE RESPECTIVE PROGRAM IN GRAPHICAL FORMATION:

clear all;
close all;
clc;

b=0.02;
g=9.81;
l=1;
m=0.1;

%initial condition
theta_0=[0;4];
%time points
t_span=linspace(0,10,500)
[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')

Above expression will provide a graphical view which is stated below

AND HERE WE HAVE THE PROGRAM FOR PENDULUM EXECUTES HARMONIC MOTION:https://www.youtube.com/watch?v=FMZakkvS784

DESCRIPTION:for all damping equation do have vibration which is of 3 types which are:

UNDER VIBRATION

CRITICAL VIBRATION

OVER VIBRATION

vibration can be reduced can't be terminated in any cause

DAMPER are used due to shock absorbing capability such as in GUN,CAR SEATS ETC

clear all
close all
clc
%input
b=0.05;
g=9.81;
l=1;
m=0.1;
%initial condition
theta_0=[0;4];



%time points
t_span=linspace(0,20,200);
[t,results]=ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
a=1
for i=1:length(results)
    angle = results(:,1);

   x0=0;
   y0=0;

   x1=l*sin(results(i,1));
   y1=-l*cos(results(i,1));
   plot(x1,y1,'o','markersize',25,'MarkerFaceColor','red','color','r')
   line([-1 1],[0 0],'linewidth',3,'color','y')
   hold on
   plot([x0 x1],[y0 y1],'color','g')
   hold off
   axis([-1.5 1.5 -2 1])
  
   
   
   
  P(a)=getframe(gcf);
  a=a+1
  
end

movie(P)
videofile=VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,P)
close(videofile)
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.