All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
- 1. Aim: To solve an ODE equation to plot the graph and do an animation of the motion of a pendulum corresponds to the displacement value. - 2. Objectives: - To solve an ODE equation. - To generate the plot of displacement and velocity. - To get an animation of the motion of pendulum with respect…
Neel sanap
updated on 18 Sep 2020
- 1. Aim: To solve an ODE equation to plot the graph and do an animation of the motion of a pendulum corresponds to the displacement value.
- 2. Objectives:
- To solve an ODE equation.
- To generate the plot of displacement and velocity.
- To get an animation of the motion of pendulum with respect to displacement.
- 3. Method:
- 3.1 Generate the plot using ODE expression:
- ODE has a lot of application in vehicle dynamics, where suspension system can be modelled as a spring, mass and damper. We can solve the ODE and figure out how the behaviour will be.
- There are two 1st order ODE, one for displacement and 2nd for velocity.
- To solve the ODE, first, it has to be converted into a 1st order differential equation. For example, if we are having a 3rd order differential equation, then we have to generate 3 1st order equation in order to solve.
- 3.2 Generate the motion of a pendulum and capture the movie:
- In order to generate the motion of a pendulum, as it is a continues process which is repeated until some values a ' for loop' is used in order to simulate the motion.
- Here the motion is generated by continuously changing the values of x and y component, that is the reason the iteration value for 'for loop' is taken as displacement and it is stored in 'ang_displacement'.
- The displacement has two values in its matrix which are displacement and velocity. In order to assign the displacement values, results(;,1) is used. So that all the values of displacement are stored in 'ang_displacement'.
- 3.3 'marker' command:
- In order to plot the bob of the pendulum 'marker' command is used. 'marker' command has its syntax need to be followed and it is shown below.
- 'markersize' is the command used to give a size to be bob and 'markerfacecolor' is used to give a color to the bob.
- Different shapes can be given to be the marker, here as 'o' is used in order to give a round command, however other shapes can be given.
close all
clear all
clc
%input parameters given
b=0.05;
g=9.81;
l=1;
m=0.1;
%initial condition where 0 is displacement and 3 is velocity
theta_0 = [0;3];
% time span of 0 to 20 sec
t_span = linspace(0,20,100);
ct = 1;
% solve ode
[t,results] = ode45(@(t,theta) ode_func(t,theta), t_span, theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
% Assigning the values of displacement in the result matirx to ang_displace
ang_displacement = results(:,1);
figure(2)
% animation creation
for i = 1:length(ang_displacement)
ANG_DISP = ang_displacement(i); %each vaalues of angular displacements are assigned to ANG_DISP
x0 = 0;
y0 = 0;
x1 = -l*sin(ANG_DISP);
y1 = -l*cos(ANG_DISP);
% "-" sign is given it order to represent the string in downward
% direction or in 3rd quadrant
plot([-0.5 0.5],[0 0],'color','g','linewidth',3);
hold on
plot([x0 x1],[y0 y1],'color','r','linewidth',3);
hold on
plot(x1,y1,'linewidth',3,'marker','o','markersize',15,'markerfacecolor','r');
hold off
axis([-1.5 1.5 -1.5 1.5])
pause(0.001)
M(ct) = getframe(gcf); % this cammand will capture all the frames
ct = ct+1;
end
movie(M) % matlab will generate movie with all frames
videofile = VideoWriter('pendulum_simulation.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Output plot showing displacement and velocity variation. |
- Problems encountered:
In the 'ode_func' only two parameters are defined (t, theta) and here while giving input b,g,l,m are also given which generated the errors. All other values are already mentioned. |
Values of x1 are mentioned positive which resulted in the motion of the pendulum in an upward direction, whereas the requirement is in a downward direction. |
In order to plot the motion, 'hold on' command is used to generate continues clips. However, at the end 'hold off' command is needed to be mentioned to avoid the error as shown above. |
- 4. Learning outcome:
- Generating the animation for a pendulum.
- Introduction to the ode45 and Anonymous function.
- Use of 'for loop' for animation generation.
- 5. Conclusion:
- For the generation of an animation a 'for loop' is used which result in a continuous iteration until the condition gets false and give an output.
- While using an 'ode' command, the equations has to be solved into 1st order ODE.
Youtube video link: https://youtu.be/nlPZmqsLCGU
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...
Photo Realistic Rendering
Title: modelling of the chopper model in Solidworks. - Objectives: - To model different parts of the chopper along with proper constraints. - To do assembly of the chopper model. - Perform the rendering operations. - Introduction: - Designing or modelling of a vehicle generally starts with the styling team,…
01 Sep 2021 10:25 AM IST
Benchmarking
2. Prepare a report explaining what is benchmarking. Benchmarking involved a comparison between similar products on some dimensions of performance. It can be used to compare the availability and delivery of features in a product and in this form often provide the basis of consumer tests and review. These look at products…
30 Jun 2021 05:26 AM IST
Design of backdoor
- Aim: To design the back door of an automobile using the styling surface along with necessary reinforcement and embosses. - Method: - Back door: - A car door is a type of door, typically hinged, but sometimes attached by other mechanisms such as tracks, in front of an opening that is used for entering and exiting a vehicle.…
24 Jun 2021 06:51 PM IST
Roof challenge
- Aim: To design the Automotive roof rail and all the necessary components to improve the strength of the roof as per the master section. - Method: - An automobile roof or car top is the portion of an automobile that sits above the passenger compartment, protecting the vehicle occupants from sun, wind, rain, and other…
22 May 2021 06:44 AM 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.