All Courses
All Courses
AIM:To create a program of simple pendulum with second order differential equation by using the matlab through given conditions. EXPLANATION OF SECOND ORDER DIFFERENTIAL EQUATION: The second order differential equation is …
Mohmmed Riyaz
updated on 02 Mar 2022
AIM:To create a program of simple pendulum with second order differential equation by using the matlab through given conditions.
EXPLANATION OF SECOND ORDER DIFFERENTIAL EQUATION:
The second order differential equation is
....equation1.
In above equation,
g=gravity in m/s2,
L=length of the pendulum in m,
m=mass of the pendulum,
b=damping co-efficient,
let us assume that,
θ=θ1
therfore
dθ/dt=(dθ1/dt)=θ2
...equation2
d²θ/dt²=(d²θ1/dt²)=d/dt(dθ/dt)=d/dt(θ2)
...equation3
substituting equation2 in equation1 we get
d²θ1/dt²+b/m(dθ/dt)+g/l(sinθ1)=0
substitute the assumed condition d/dt=θ2
dθ2/dt+b/m(θ2)+g/l(sinθ1)=0
therefore,
dθ2/dt=-b/m(θ2)-g/l(sinθ1)
EXPLANATION OF CODES:I can use the second order differential equation.
1.function command is used.function is a file named.m,that accept an input vector and calculates the average of the values,and return a single result.
2.ode45 is used which is enabled value.
3. code @ is used which is repeat the functions.
4.plot command is used to get the velocity and dispalcement along with time is plotted.
5.To create a movie by using a command of vedio file,vedio writer and collection of frames to get a vedio.
FUNCTION PROGRAM CODE:the below function program is used in the program.
function dtheta_dt = ode_func2(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
MAIN PROGRAM CODE:
%for creating a pendulum using second order differential equation
clear all
close all
clc
%condition given
%the damping co-efficient
b=0.05;
%gravity in m/s^2
g=9.81;
%length of pendulum in m
l=1;
%mass of pendulum
m=1;
%motion between them is 0-20sec
%for angular displacement=0 and angular velocity=3 at time=0
theta_0 = [0;3];
%initial tikme taken t
t_span=linspace(0,20,400);
[t,results]=ode45(@(t,theta)ode_func2(t,theta,b,g,l,m),t_span,theta_0);
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('time taken in s')
ylabel('angular displacement and angular velocity')
legend('angular displacement and angular velocity','time')
%plotting of pendulum
figure(2)
%assume origin
x0=0;
y0=0;
ct=1
for v=1:length(t)
x1=l*sin(results(v,1));
y1=-l*cos(results(v,1));
plot([x0 x1], [y0 y1],'linewidth',4)
hold on
plot([-0.2 0.2], [0 0],'LineWidth',4)
plot (x1,y1,'o','MarkerSize',15,'MarkerFaceColor','w')
axis([-1 1 -1 1])
hold off
grid on
pause (0.0008)
M(ct)=getframe(gcf);
ct=ct+1;
end
%vedio file
movie(M);
vediofile=VideoWriter('ode_func2.avi','Uncompressed AVI')
open(vediofile);
writeVideo(vediofile,M);
close(vediofile);
OUTPUT:
ERRORS:1.The errors i have faced is missed the comma operator,identified by the error showed in the line25 with column17
2.another error i have faced is value is not a numeric scalar.
3.another error is unrecognized variable that should be identified by showing in output after identified it is solved.
after sove this error the output is generated in below image
PLOTTING:first we create a figure and use plot of angularvelocity,displacement and time.
VEDIO:finally the vedio is created.
https://drive.google.com/file/d/1NzXaN_Rpo7SHxb-2nSgreUjNOfA6cxTd/view?usp=sharing
CONCLUSION:The program has been created successfully and creating vedio of simple pendulum by using a matlab.
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
AIM: To develop the forward energy-based fuel Consumption model of a P1 hybrid vehicle by using the matlab and simulink. Overview: 1. Hybrid Electric vehicle: Using the Two or more energy sources to propulsion system in driving is called the Hybrid Electric Vehicle. Conventionally,petroleum fuel based energy source (Petrol,deisel,etc..)via…
30 Jun 2022 03:17 PM IST
Project 2 Adaptive Cruise Control
EV BATCH17 AIM: To develop a model of adaptive cruise control by using the matlab. Objective: Development of a MATLAB Simulink Model for Adaptive Cruise Control feature as per the requirement document following Model Based Development(MBD) related process.SLDD creation,configuration parameter changes,Model advisor check…
27 Jun 2022 07:56 AM IST
Project 1 (Mini Project on Vehicle Direction Detection
AIM: To develop the model of vehicle direction by using the matlab. OBJECTIVE: The objective of this project is to create a MBD complaint MATLAB Simulink model for a vehicle direction dectection as per the requirement specified. Tag the requirements to the simulink model;Requirement 1 & Requirement 2 are tagged…
26 Jun 2022 06:30 AM IST
Project 2 Thermal modeling of battery pack
EV BATCH17 AIM: To design a 10 series lithium ion battery model,simulate the thermal effects by using the matlab. abstract: Lithium ion (Li-ion) battery pack is a complex system consisting of numerous cells connected in parallel and series. The performance of the pack is highly dependent on the health of each individual…
18 Jun 2022 09:46 AM IST
Related Courses
0 Hours of Content