Challenge

Week 3 - Solving second order ODEs

Aim,

A program to solve the following ODE and will stimulate the simple pendulum motion by using given parameters

in Matlab.

Objective,

  • To write a program to solve the following ODE using represents the equation of simple penudlam motion to calculating damping wrt angular velocity and angular dispalcement.
  • To write a program that stimulate the animation of simple pendulum

Introduction

Simple Pendulum,

Simple pendulum is an ideal pendulum consisting of a point mass suspended by a weightless inextensible perfectly flexible thread and free to vibrate without friction —distinguished from physical pendulum.It is another mechanical system that moves in an oscillatory motion.

First Order Diffrential Equation,

A first-order differential equation is defined by an equation: dy/dx =f (x,y) of two variables x and y with its function f(x,y) defined on a region in the xy-plane. It has only the first derivative dy/dx so that the equation is of the first order and no higher-order derivatives exist. The differential equation in first-order can also be written as;

y’ = f (x,y)

(d/dx) y = f (x,y)

Second Order Diffrential Equation;

The order of a differential equation is the highest-order derivative that it involves. Thus, a second order differential equation is one in which there is a second derivative but not a third or higher derivative.

the equation is,

Expressions,

b- Damping co efficient

g- gravity i m/s

m-mass of the bob in kg

l-length of the pendulam in m

the derivation of second order diffrential equation,

Program,

By using second order diffrential equation to determine bob position with respect to time,angular dispalcement and angular velocity of simple pendulam by using given parameters such as,

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s2.

time= 0-20s

Intian Angular displacement= 0

Intial angular velocity= 3 rad/ sec at time 0.

First of all we create a function using diffrential equation,

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

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

Then we have to find out the dambing of angular velocity and angular displacement of the bob by using above parameters and initial conditions,

clear all
close all
clc

%Inputs
b=0.05; % Dambing Coefficient
g=9.81; % Acceleration due to Gravity 
m=1;    % Mass on the ball
l=1;    %lenth of the pendulam

%Initial Condition for angular displacement is 0 and angular velocity is 3
theta_0=[0;3];

%Time Position to find motion
t_span=linspace(0,20,300);

%To Solve second order diffrential equation using ode45 solver
[t,solu]=ode45(@(t,theta) Fun_ode(t,theta,b,m,g,l),t_span,theta_0);

%plotting angular displacement and angular velocity wrt time
figure(1)
plot(t_span,solu(:,1))
hold on
plot(t_span,solu(:,2));

%Now animate the simple pendulam by using angular displacement column
%matrix

c=1;
%using for loop to find out coordinates of simple pendulam
for i= 1:length(solu)
    x0=0; %Initial value of x coordinates
    y0=0; %Initial value of y coordinates
    x1=l*sin(solu(i));  % Another coordinates
    y1=-l*cos(solu(i));
%Plotting 
figure(2)
plot([-1.5 1.5],[0 0],'linewidth',2);% To Create line for statring point of pendulam
hold on
plot([x0 x1],[y0 y1]);
plot([x0 x1],[y0 y1],'Color','r','linewidth',2);
% To create a bob using marker
plot(x1,y1,'Marker','o','markersize',20,'MarkerFaceColor','b');
hold off
axis([-1.5 1.5 -1.5 0.5]);%Giving axes to plotting for simple pendulam
grid on
xlabel('x')
ylabel('y')
title('SimplePendulam')
pause(0.03);
M(c)=getframe(gcf);
c=c+1;
end

%Creating Animation of Simple pendulum
movie(M)
videofile=VideoWriter('Simple Pendulum Motion.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);

Explanations about program

  • First we need to create a function using second order diffrential equations with mass, length, gravity and dambing coefficient, and then have to give inputs of parameters, initial condition of angular displacement ,angular velocity (theta), and need time to calculation position of bob dambing. After that using ODE45 solver to calculate the dambing wrt time by usinng functions and parameters.After calculating angular velocity and angular displacement wrt time to create a plot in each column.
  • Then have to create the animation of simple pendulam with angular dispalcement,using for loop wrt to output of angular displacement to plot the position of pendulum with the limits using initial and final coordinates, to fix the axes limits for the pendulam locate the sencon and third quadrant.
  • Then we plot a Line for fixed point of pendulum, after to create a bob using marker with size and color like to show like a pendulam.After it all that we creta animation Movie as shown a Dambing Simple pendulam.

Graph of time and Angular displacement and velocity,

Link:

The link that we uploaded in youtupe,

Simple Pendulum Motion

Workspace Screenshot,

Conclusion;

1. Finally we plotted the Graph of Angular velociity and angular displacement wrt to time using ODE4 solver in Matlab.

2. The created the animation of Simle pendulum motion with damping and uploaded in youtupe.

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.