All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To create a program to solve the second order ODE of motion of a simple pendulum with damping by using Matlab. OBJECTIVE: 1. To write a program that solves the second order ODE 2. To create an animation of the motion of simple pendulum using Matlab. THEORY: ORDINARY DIFFERENTIAL EQUATION:…
Akash M
updated on 25 Jun 2021
AIM:
To create a program to solve the second order ODE of motion of a simple pendulum with damping by using Matlab.
OBJECTIVE:
1. To write a program that solves the second order ODE
2. To create an animation of the motion of simple pendulum using Matlab.
THEORY:
ORDINARY DIFFERENTIAL EQUATION:
An ordinary differential equation (ODE), in Mathematics, is an equation which consist of one or more functions of one independent variables along with the derivatives.A differntial equation is an equation that contains a function with one or more derivatives. But in this case the word ordinary is used for derivative of the functions for single independent variable. In case of other types of diffrential equations, it is possible to have derivatives for functions more than one variables. The differential equations are classified as Linear, Non-linear, Homogenous and Non homogenous equations. Based on the order of equations , they are aslo classified as first order ordinary differential equation and second order differential equation or 'nth' order equation. The ODE is basically used to describe the transient behaviour of a system and one of its example is simple pendulum.
SIMPLE PENDULUM:
A simple pendulum is one which can be considered to be a point mass suspednded from a string or rod. The block diagram of simple pendulum shown in the below figure.
The differential equation for the motion of a simple pendulum with damping is as follows,
Where,
θ = angular displacement of the pendulum;
b = damping co-efficient;
m = mass of thr pendulum(kg);
g = acceleration due to gravity(m/s^2);
l = length of the pendulum(m);
DEREVATION:
by the above equations,
Matlab Program to solve second order ODE:
% program to solve second order ODE of a simple pendulum
clear all
close all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
% initial condition
theta_0 = [0;3];
% times point
t_span = linspace(0,20,600);
% solve ODE
[t, results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span, theta_0);
% plotting of Angular displacement and Angular velocity
figure(1)
plot(t,results(:,1),'linewidth',2);
hold on;
plot(t,results(:,2),'linewidth',2);
axis([0 20 -4 4]);
xlabel('time(sec)');
ylabel('Anguar displacement and Angular velocity');
grid on
title('Damping effect in simple pendulam');
legend('Anguar displacement','Angular velocity');
% contour command
ct = 1;
for i = 1:length(t_span);
x0 = 0;
y0 = 0;
x1 = l*sin(results(i,1));
y1 = -l*cos(results(i,1));
% plotting the motion of pendulum
figure(2)
plot([x0 x1],[y0 y1],[-0.5 0.5],[0 0],'linewidth',2)
hold on
plot(x1,y1,'marker','o','markersize',25,'markerfacecolor','g')
axis([-1.5 1.5 -1.5 0.5])
grid on
title('Motion of Simple pendulum with damping effect');
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
hold off
end
% Animation
movie(M)
videofile = VideoWriter('simple_pendulum.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
PROCEDURE:
1.To create a new program open new script file and
2.The code starts with clear all which is used to clear the data stored in the workspace, close all which is used to close all the plots and figures and clc which is used to clear the command window.
3.Enter all the input values of b,g,l and m and enter the initial conditions for angular displacement (θ1 = 0) and angular velocity (θ2 = 3 rad/s) to the variable 'theta_0'.
4.Use linspace command to range the t_span value i.e, the time span of the motion of simple pendulum, which is taken to be 20 seconds with 600 values.
5.To establish the relation between all the input values in second order ODE a different function code is written, which is as follows,
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
6.Here the first value of row matrix is defined as 'theta1' and the second value is defined as 'theta2'. The function code is based on the matrix which we derived.
7.E enter all the corresponding equations and relations. The function is named as 'ode_func' is then called in the main code with a special syntax 'ode45'.
8.The [t,results] contains the result which we need to plot with respect to the time in which results(1) contains angular displacement values in radian and results(2) contains angular velocity values in radian . we can use this to calculate different values of angular displacement and angular velocity.
9.Use this result to plot the graph of angular displacement and angular velocity with respect to time.
10.Then initialize the counter variable 'ct' that simply increments by a specific step value in every iteration of a loop.
11.Use 'for' loop to assign all the values of 't_span' to a variable 'i' one at a time.
12.To form the link or string of the pendulum, enter all the coordinates of the points of a line (x0,y0,x1,y1).
13.Use 'maker' command to form a circle or the bob of the pendulum and the counter is increment by 1.
14.Use 'pause' command to acieve better animation speed.
15.Use 'getframe' command to capture the motion of the lines and stored in variable M.
16.Use 'movie' command to make a movie with all the frames stored in a variable M.
17.To save this movie, use 'videofile' command which has the option to store the video in an 'uncompressed avi' format along with the file name.
18.Then the vedio file will open after the plot.
OUTPUT:
RESULT:
1.From the graph, the periodic curve of angular displacement and angular velocity reduces with respect to the time.
2.The animated vedio of the motion of simple pendulum given in the link. https://youtu.be/0PfNJa1ZDGQ
CONCLUSION:
Here we have writen the program to solve the second order ODE and created the animated vedio of the motion of simple pendulum. We can use the same method for other higher oreder ODE.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project - 2 - Generating the report for hypermesh file
Aim: To generate the report for hypermesh file Objective: To create an ergonomic and visually appealing excel (.xlsm) report that contains following information about your model: User name, date, time Profile/deck; count of component, prop, material, elements Count of empty comp/prop/mats Elements…
20 Dec 2021 07:48 AM IST
Project 1- Building a Master TCL/TK Macro
Aim: To create a master TCL/TK macro that performs several operations such as finding and correcting normals, final checks, creating components, reflecting geometry, creating connections and identify identical components. Objective: It should contain buttons that will call all utilities created as assignments during…
10 Dec 2021 05:13 AM IST
Week - 9 - Reflecting the geometry
Aim: To create a code that performs reflecting the geometry Objective: Create a macro that will reflect given multicomponent FE part with ease It should be independent of deck The inputs should be original CAD comp, reflected CAD comp and original FE comps …
07 Dec 2021 03:01 PM IST
Week - 12 - Creating the locator, writing and reading the node data
Aim: To create a code that performs connections, identify the identical components and reading nodes from a file. Objective: Create a macro that builds a GUI containing 4 buttons. Component creator, weld, xloc, yloc, zloc. Upon pressing the buttons corresponding 1D element must be created…
07 Dec 2021 12:35 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.