SlideShare a Scribd company logo
1 of 2
clear all; close all; clc;
tspan=linspace(0,2.100) % time span ranges from 0 to 15 sec
% Defined the Inintial conditions
x0=[6;-1;1;1] % x1(0), x2(0), x1prime(0), x2prime(0);
%ode code
[t,x]= ode45(@odefun,tspan,x0) %odefun-name of function
%make plots
plot(t,x(:,1)) % first degree
hold on % add second plot
plot(t,x(:,2))% plot second degree
legend ('x1-cart','x2-pendulum') % created the legends on
the graph
% step 4: creating the derivaticce function
function dx2dt= odefun(t,x) % argument are t, x
% we defiend the parameters values
m1 = 0.5; % mass of cart
m2 = 0.2; % mass of pendulum
L=0.3;
Izz =0.006;
g = 9.81;
f=1
p1 = ((m1+m2)*(Izz+(m2*(L^2))))-((m2^2)*(L^2));
% initializing the column vector for the output derivative
dx2dt= zeros(4,1);
dx2dt(1)=x(3);
dx2dt(2)=x(4);
dx2dt(3)= (f/(m1+m2))-((((m2*L)^2)*g)/p1)*x(2); % x double
derivative equation
dx2dt(4)=m2*g*L*x(2) -((m2*L*f)/(m1+m2))/p1 ; % Phi double
derivative equation
% dx2dt is the output to our ode function
end
ode45 task.docx

More Related Content

Similar to ode45 task.docx

This problem illustrates one of the possible pitfalls of blindly appl.pdf
This problem illustrates one of the possible pitfalls of blindly appl.pdfThis problem illustrates one of the possible pitfalls of blindly appl.pdf
This problem illustrates one of the possible pitfalls of blindly appl.pdf
arihantmum
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
asghar123456
 
Adaptive dynamic programming for control
Adaptive dynamic programming for controlAdaptive dynamic programming for control
Adaptive dynamic programming for control
Springer
 

Similar to ode45 task.docx (20)

DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
 
residue
residueresidue
residue
 
Application of Differential Equation
Application of Differential EquationApplication of Differential Equation
Application of Differential Equation
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
This problem illustrates one of the possible pitfalls of blindly appl.pdf
This problem illustrates one of the possible pitfalls of blindly appl.pdfThis problem illustrates one of the possible pitfalls of blindly appl.pdf
This problem illustrates one of the possible pitfalls of blindly appl.pdf
 
Computational Method to Solve the Partial Differential Equations (PDEs)
Computational Method to Solve the Partial Differential  Equations (PDEs)Computational Method to Solve the Partial Differential  Equations (PDEs)
Computational Method to Solve the Partial Differential Equations (PDEs)
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Matlab file
Matlab file Matlab file
Matlab file
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Dsp iit workshop
Dsp iit workshopDsp iit workshop
Dsp iit workshop
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
Cs580
Cs580Cs580
Cs580
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
Adaptive dynamic programming for control
Adaptive dynamic programming for controlAdaptive dynamic programming for control
Adaptive dynamic programming for control
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 

Recently uploaded

21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
mikehavy0
 

Recently uploaded (20)

21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
DBMS-Report on Student management system.pptx
DBMS-Report on Student management system.pptxDBMS-Report on Student management system.pptx
DBMS-Report on Student management system.pptx
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Databricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfDatabricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdf
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 

ode45 task.docx

  • 1. clear all; close all; clc; tspan=linspace(0,2.100) % time span ranges from 0 to 15 sec % Defined the Inintial conditions x0=[6;-1;1;1] % x1(0), x2(0), x1prime(0), x2prime(0); %ode code [t,x]= ode45(@odefun,tspan,x0) %odefun-name of function %make plots plot(t,x(:,1)) % first degree hold on % add second plot plot(t,x(:,2))% plot second degree legend ('x1-cart','x2-pendulum') % created the legends on the graph % step 4: creating the derivaticce function function dx2dt= odefun(t,x) % argument are t, x % we defiend the parameters values m1 = 0.5; % mass of cart m2 = 0.2; % mass of pendulum L=0.3; Izz =0.006; g = 9.81; f=1 p1 = ((m1+m2)*(Izz+(m2*(L^2))))-((m2^2)*(L^2)); % initializing the column vector for the output derivative dx2dt= zeros(4,1); dx2dt(1)=x(3); dx2dt(2)=x(4); dx2dt(3)= (f/(m1+m2))-((((m2*L)^2)*g)/p1)*x(2); % x double derivative equation dx2dt(4)=m2*g*L*x(2) -((m2*L*f)/(m1+m2))/p1 ; % Phi double derivative equation % dx2dt is the output to our ode function end