Challenge

Week 4.1 - Solving second order ODEs

Aim:To simulate the motion of a simple pendulum and to animate using the video file.

Objectives:

  • Write a program to solve the ODE
  • Plot the displacement v/s time and velocity v/s time graphs
  • Create an animation of the motion of the pendulum

Introduction:

In Mathematics an ordinary differential equation is a differential equation containing one or more functions of one independent variable and the derivatives of those functions. The term ordinary is used in contrast with the term partial differential equation which may be with respect to more than one independent variable.

Any derivatives with respect to the independent variable must have an order no higher than 2">2 to be considered a second-order ordinary differential equation.
We may solve a wide variety of engineering systems, including harmonic, vibration, damping, etc., with the aid of the ordinary differential equation.
In engineering, a wide variety of systems are modelled using second-order linear differential equations.

A straightforward pendulum consists of a mass "m" fixed at a pivot point and suspended on a string of length "l." The pendulum will periodically swing back to the front when it is released after being shifted to an initial angle of "."

θ′=ωω′=−gLθ. Notice that (θ′,ω′) is given as a function of (θ,ω). The entire motion of the pendulum is determined if we know (θ,ω) at some instant.

Equation:

The equation of second order ode for simple pendulum goes as:

We are going to use the 2nd order ODE equation to find out the velocity and position of the pendulum ball with respect to time.

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

Inputs are taken as given in the problem

L = 1meter

m= 1kg

b=0.05

g=9.81m/s^2

Initial conditions are taken as

Angular displacement =0;

Angular velocity=3 rad/sec,at time t=0;

the time motion given is between 0-20sec

 %Program to solve the ODE and simulatethe pendulum motion

 
clear all
close all
clc

 
%Inputs
% damping coefficient value
b = 0.05;
%Gravitational value (m/s^2)
g = 9.80;
%Length of the pendulum (m)
l = 1;
%mass of the body (kg)
m = 1;

 

 
%First condition for displacement and velocity
theta_0 = [0;3];

 
%Time span points
t_span = linspace(0,20,400);

 
%Solving ODE
[t,results] = ode45(@(t,theta) ode_function(t,theta,b,g,l,m),t_span,theta_0)

 
%Plotting
figure(1)
plot(t,results(:,1),'color','r')
hold on
grid on
plot(t,results(:,2),'color','g')
xlabel('Time')
ylabel('Plot')
legend('Displacement','Velocity')

 
figure(2)
plot(results(:,1),results(:,2))
xlabel('position-radian')
ylabel('angular velocity - radians/sec')
title('angular velocity')
legend('angular velocity')

 
figure(3)
ct = 1;
for i = 1:length(results(:,1));
THETA_1 = results(i,1);
% Initial co-ordinates
x0 = 0;
y0 = 0;
 
x1 = 1*sin(THETA_1);
y1 = -1*cos(THETA_1);
 
%Plot
plot([-0.5 0.5],[0,0],'color','c')
line([x0 x1],[y0,y1],'color','b')
hold on
plot(x1,y1,'marker','o','markersize',25,'markerfacecolor','r')
grid on
title('Moving Pendulum with function of time')
axis ([-1.5 1.5 -1.5 1])
hold off
pause(0.001)
M(ct) = getframe(gcf);
ct = ct+1;
end

 ​
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.