Solving second order ODEs
AIM: to create a program in matlab to solve the 2nd order ode of motion of a simple pendulam with damping.
THEORY :
In matheamatical an ordinary diffrential equation (ode) is adiffrential equatons contaning one or more function of one indipendent variable and the derivatives of those function.
Equation for second order
b = damping coefficient.
m = mass of the pendulam in kg.
This diffrential equation is 2nd order equation
Derivation for code simplify :
Angular displacment=theta 1
And angular velocity=
Substituing these in the 2nd order ode for a simple pendulam .
This is a 1st order differntial equation in the form of a matrix,
=
writing these equation in the form of a matrix ,
Where,
Angular displacment of the pendulam,
= Angular velocity of the pendulam,
By the solving equation in matlab , we can get the value angular velocity and angular displacment W.R To Time.
MATLAB PROGRAM:
clear all
close all
clc
b=0.05; % damping coefficient.
g=9.81; % acceleration due to gravity in
l=1; % length of the pendulam in M.
m=1; % mass of pendulam in KG.
ODE FUNCTION
function [dtheta_dt]=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);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end
%initial condition
theta_0=[0;3];
%time points
t_span=linspace(0,20,100);
%solve ode
[t results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
%plotting
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
title('bf second order ode')
xlabel('bf Time')
ylabel('bf Velocity')
legend('Displacement','Angular velocity')
grid on
disp=results(:,1);
ct=1;
for i=1:length(t_span);
x0=0;
y0=0;
x1=l*sin(disp(i));
y1=-l*cos(disp(i));
figure(2)
plot([-2 2],[0 0],'linewidth',5)
hold on
plot([x0 x1],[y0 y1],'-o','markersize',3,'linewidth',5,'color','r');
plot(x1,y1,'-o','markersize',20,'markerfacecolor','k');
axis([-1.5 1.5 -1.5 1.5])
pause(0.03)
hold off
M(ct)=getframe(gcf)
ct=ct+1;
end
movie(M)
v=VideoWriter('pendulam.avi');
open(v)
writeVideo(v,M)
close(v)
Results;
- As seen in the graph , the pereodic curve of angular displacment and angular velocity reduce W.R Time . Thisb is manily due to the damping factor.This is the motion of simple pendulam is called as damped simple arnic motion.
- From the animation of motion of the simple pendulam , it can be conculded ,as the damping coefficient is increase ,the motion of the pendulam . Also increase in damping coefficient reduce the time taken by pendulam to reach equliliburium position.
ERRORS:-


YOU TUBE LINK
so i submitted all the things which is required.and i hope this should be satisfy you and i will get the full marks over here.
THANK YOU
SKILL LYNC