All Courses
All Courses
https://drive.google.com/file/d/1De3PEgajegZQYvHxh__Jjih9lCM_TY55/view?usp=sharing %clearing line screen,command line,work space and closing all plots clear all close all clc %inputs b=0.05; g=9.81; % specific gravity in m/s^2 l=1; %length of string in m m=1; % mass in kg % initial condition % for solving first order ode…
Mohan Babu H
updated on 11 Jul 2021
https://drive.google.com/file/d/1De3PEgajegZQYvHxh__Jjih9lCM_TY55/view?usp=sharing
%clearing line screen,command line,work space and closing all plots
clear all
close all
clc
%inputs
b=0.05;
g=9.81; % specific gravity in m/s^2
l=1; %length of string in m
m=1; % mass in kg
% initial condition
% for solving first order ode it is required value of displacement and velocity
% initial condition of pendulum is 0
% initial velocity is 3m/s
theta_0=[0;3];
%time intervals
t_span=linspace(0,20,300);
% solving ODE
%[time,results]=ode45('challenge_2nd_ode',t_spam,theta_0);
[t,results]=ode45(@(time,theta)ode_function(time,theta,b,g,l,m),t_span,theta_0);
% plotting
subplot(5,4,[13,14,17,18]);
plot(t,results(:,1),'color','b');
hold on
plot(t,results(:,2),'color','r');
hold off
subplot(5,4,[15,16,19,20]);
plot(results(:,1),results(:,2));
ylabel('position-radian');
xlabel('angular velocity');
ct=1;
for i=1:length (results(:,1))
x0=0;
y0=0;
x1=1*sin (results(i,1));
y1=-1*cos (results(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',2,'color','b');
% r=0.075; % plotting circle and then mapping the center of string
% cir_deg=linspace(0,2*pi,1000);
% xc=r*cos(cir_deg);
% yc=r*sin(cir_deg);
% plot(x1+xc,y1+yc,'linewidth',2)
% hold off;
plot (x1,y1,'-o','markers',20,'markerfacecolor','r'); %plotting the bob using marker and facecolor
% r=0.25; % plot a curved rectangle snd color its inner
% rectangle('position',[(x1-(r/2)),(y1-(r/2)), r,r],'curvature',[1,1],'facecolor','r',linewidth,',3)
% hold on
% axis equal
grid on;
axis([-1.5 1.5 -1.5 1]);
pause(0.0003);
hold off
## q(ct)=getframe(gcf);
Text=sprintf("pendulum%d.png",ct);
saveas(1,Text)
ct=ct+1;
end
% movie(q)
% video file=videowriter('pendulum_damped.avi','uncompressed avi');
% open giffile
% writegif(giffile,q)
%close(giffile)
% function of pendulum oscillation with for loop
function[dtheta_dt]=pendulum_damped_ode(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
%clearing line screen,command line,work space and closing all plots
clear all
close all
clc
%inputs of pendulum geometric
b=0.05;
g=9.81; % specific gravity in m/s^2
l=1; %length of string in m
m=1; % mass in kg
% initial condition
% for solving first order ode it is required value of displacement and velocity
% initial condition of pendulum is 0
% initial velocity is 3m/s
theta_0=[0;3];
%time intervals
t_span=linspace(0,20,300);
% solving ODE
%[time,results]=ode45('challenge_2nd_ode',t_spam,theta_0);
[t,results]=ode45(@(time,theta)ode_function(time,theta,b,g,l,m),t_span,theta_0);
% plotting
subplot(5,4,[13,14,17,18]);
plot(t,results(:,1),'color','b');
hold on
plot(t,results(:,2),'color','r');
hold off
subplot(5,4,[15,16,19,20]);
plot(results(:,1),results(:,2));
ylabel('position-radian');
xlabel('angular velocity');
ct=1;
for i=1:length (results(:,1))
x0=0;
y0=0;
x1=1*sin (results(i,1));
y1=-1*cos (results(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',2,'color','b');
% r=0.075; % plotting circle and then mapping the center of string
% cir_deg=linspace(0,2*pi,1000);
% xc=r*cos(cir_deg);
% yc=r*sin(cir_deg);
% plot(x1+xc,y1+yc,'linewidth',2)
% hold off;
plot (x1,y1,'-o','markers',20,'markerfacecolor','r'); %plotting the bob using marker and facecolor
% r=0.25; % plot a curved rectangle snd color its inner
% rectangle('position',[(x1-(r/2)),(y1-(r/2)), r,r],'curvature',[1,1],'facecolor','r',linewidth,',3)
% hold on
% axis equal
To save output of pendulum images as png
grid on;
axis([-1.5 1.5 -1.5 1]);
pause(0.0003);
hold off
## q(ct)=getframe(gcf);
Text=sprintf("pendulum%d.png",ct);
saveas(1,Text)
ct=ct+1;
end
To make gif file the command as shown
% movie(q)
% video file=videowriter('pendulum_damped.avi','uncompressed avi');
% open giffile
% writegif(giffile,q)
%close(giffile)
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 2 : Basic Calibration of Single cylinder SI-Engine
Aim: * The Main objective of this project is to set up and run the model for a single cylinder four stroke SI Engine at 1800 rpm * To run the same model at 3600 rpm and increases the power - output by 10% Introduction: The Spark ignition (SI) engine is an internal combustion engine , where the air fuel mixture…
06 Jan 2023 01:38 PM IST
Week 1 : Exploring the GUI of GT-POWER
Aim: To Explore the GUI of GT-suite and GT-power and explaining the listed the modules in a brief description. GT-Suite: The tool which is used to industry leading simulation tool with capabilities and libraries aimed at a large set of applications in industries. It offers engineering functionalist ranging fast concept…
22 Nov 2022 02:01 PM IST
Week 11: Project 2 - Emission characterization on a CAT3410 engine
Aim: To Perform Emission Characterization on a CAT3410 Engine. Objective: To run a 3D Simulation of a CAT3410 Diesel Engine using two different piston bowl profiles and to understand the effect of Piston Bowl geometry on the Performance ans Emission characteristics of the Engine. Geometry: A tool called Make Engine Sector…
04 Nov 2022 10:55 AM IST
Week 10: Project 1 - FULL HYDRO case set up (PFI)
Aim: To set up a combustion Simulation with the details given in the challenge and to study different properties of combustion by Post Processing the results obtained by the calculation of the full hydrodynamic set up of the given geometry. Objective: * What is the compression ratio of this engine? * Why do…
21 Oct 2022 09:11 PM IST
Related Courses
0 Hours of Content