All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: Program to simulate the transient behaviour of a simple pendulum and to create an animation of it\'s motion. Governing Equation : …
GAURAV
updated on 05 May 2020
changes when its amplitude (θ ) is changed.
clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=1;
ct = 1;
%initial condition
%initial displacement of pendulum is zero
%we give intial angular velocity #rad/sec.
theta_0 = [0;3];
%time points
t_span = linspace(0,20,500);
%Solve ODE
[t,result] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
%here we sub plot
subplot(5,4,[13,14,17,18]);
plot(t,result(:,1),\'color\',\'b\');
hold on;
plot(t,result(:,2),\'color\',\'g\');
hold off;
subplot(5,4,[15,16,19,20]);
plot(result(:,1),result(:,2));
ylabel(\'plot\')
xlabel(\'time\')
legend(\'Displacement\',\'velocity\')
%Animation For Pendulum
ct = 1;
for i=1:length(result(:,1))
x0 = 0;
y0 = 0;
x1 = l*sin(result(i,1));
y1 = -(l*cos(result(i,1)));
subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
plot([-1 1],[0 0],\'linewidth\',4 ,\'color\',\'k\');
hold on
line([x0 x1],[y0 y1],\'linewidth\',3,\'color\',\'b\');
hold on;
plot(x1,y1,\'-o\',\'markers\',20,\'markerfacecolor\',\'g\');
grid on
axis ([-1.5 1.5 -1.5 0.5])
pause(0.03);
hold off
text = sprintf(\'pendulum%d.png\',ct);
saveas(1,text)
ct=ct+1;
end
YOUTUBE LINK FOR SIMULATION
https://youtu.be/8lth_BgifXc
Function that is used avove Programme with name ode_func.
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
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...
Week 6 - Data analysis
1. AIM:- Write a programme read data from the file containing the engine's data and plot PV diagram. 2. BODY:- import matplotlib.pyplot as plt import numpy as np from numpy import trapz import time # Basic Initilization line_count =1 crank = [] volume = [] # FILE PARSING STARTS HERE try : open('engine_data.out') except…
28 Jun 2020 02:38 PM IST
Week 5 - Curve fitting
1. What does popt and pcov mean? ANS. " popt " is an array that stores the values of the coefficients that are being passed in a given function. " pcov " is a two-dimensional array that stores the values of the estimated covariance of popt i.e the coefficients. 2. What does np.array(temperature) do?…
28 Jun 2020 01:27 PM IST
Week 3 - Solving second order ODEs
1. AIM:- Write a programme for solving second order differential equation for a pendulum and also transient behaviour of a pendulum . 2.Governing Equation : 3.OBJECTIVE OF PROJECT: To To study how the time period of a simple changes when its amplitude (θ ) is changed. 4.BODY:- import…
28 Jun 2020 12:57 PM IST
Week 2 Air standard Cycle
AIM: Write a programme for AIR STANDARD CYCLE OBJECTION: The Otto cycle is an air-standard cycle which approximates the processes in petrol or diesel engines. It is based on constant volume heat addition (combustion) and heat rejection processes, and isentropic compression and expansion. …
23 Jun 2020 02:52 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.