All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To solve an ODE and use the calculated information to animate the motion of the pendulum via matlab THEORY Pendulum have many applications and were utilized often before the digital age. They are used in clocks and metronomes due to regularity of their period. A…
Dipin K D
updated on 12 Nov 2022
AIM:
To solve an ODE and use the calculated information to animate the motion of the pendulum via matlab
THEORY
Pendulum have many applications and were utilized often before the digital age. They are used in clocks and metronomes due to regularity of their period. A simple pendulum consists of a point mass suspended on a string or wirethat has negligible mass. if the pendulum weight or bob is pulled to a relatively small angle from the vertical and let go.it will swing back and fourth at a regular period and frequency
An ordinary differential equation (ODE) is differential equation containing one or more functions of one independent variable and the derivatives of those functions. The ODE equation and the calculations
Code Explanation
%The function program
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
% solving second order ODE of pendulum
clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=1;
% initial condition
theta_0 = [0;3];
%time points
t_span = linspace(0,10,500);
%solve ODE
[t,results] = ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('Plot')
xlabel('time')
%iteration using for loop to create animation of simple pendulum
ct=1;
theta_1 = results(:,1);
for i=1:length(results(:,1))
%initial co-ordinates
x_start= 0;
y_start= 0;
theta_2 = theta_1(i);
%final co-ordinates
x_end= 1*sin(theta_2);
y_end= -1*cos(theta_2);
%ploting for animation
figure(2)
%base od pendulum
plot([-1,1],[0,0], 'linewidth',4,'color','black')
hold on
%string of pendulum
line([x_start x_end],[y_start y_end],'linewidth',6,'color','b')
hold on
%bob of pendulum
plot(x_end,y_end,'marker','o','markersize',28,'markerfacecolor','r')
axis([-2 2 -2 2])
pause(0.03)
hold off
M(ct)=getframe(gcf);
ct=ct+1;
end
%creating movie
movie(M)
videofile = VideoWriter('simple_pendulum.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
Conclusion
The x_start y_start , x_end y_end values
x_start = 0
y_start = 0
x_end = -0.7351
y_end = -0.6779
Animation Video:
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 - Rankine cycle Simulator
Aim: To calculate the performance of a Steam turbine Engine and plot the T-S and H-S diagram of a Rankine Cycle. Objective: To calculate the performance of a Steam turbine Engine.To plot the T-S and H-S diagram of a Rankine Cycle. Theory: Rankine Cycle: A rankine cycle is an idealised Thermodynamic cycle which governs…
23 Nov 2022 08:08 AM IST
Week 5 - Genetic Algorithm
AIM : To study about Genetic Algorithm and to calculate the global maxima of stalagmite function using Genetic Algorithm in MATLAB. OBJECTIVE : To study about Genetic Algorithm and Stalagmite function.To write a code in Matlab to optimise the stalagmite function and find the global maxima of the function.To plot graphs…
22 Nov 2022 07:46 PM IST
Week 4.1 - Solving second order ODEs
AIM: To solve an ODE and use the calculated information to animate the motion of the pendulum via matlab THEORY Pendulum have many applications and were utilized often before the digital age. They are used in clocks and metronomes due to regularity of their period. A…
12 Nov 2022 03:45 AM IST
Week 3.2 - 2R Robotic Arm Challenge
Aim To simulate the forward kinematics of a 2R Robotic Arm in matlab Introductiion Robots are progammable machine like some human capabilities.They are used in many industeries. These elemens can be arranged in different ways and can vary in different size. Thus robots are available in a wide variety of types in their…
02 Nov 2022 06:56 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.