Matlab 3-Higher order ODE (1)
.docx
keyboard_arrow_up
School
Auburn University *
*We aren’t endorsed by this school
Course
2010
Subject
Mechanical Engineering
Date
Feb 20, 2024
Type
docx
Pages
11
Uploaded by ChancellorKoupreyPerson1035
Name: MECH 2220 Matlab Lab 3, Fall 2020
Matlab Lab 3: Numerical Solutions to Higher Order ODE’s
Assigned: 11/02/ 2020
Due: 2 weeks from the lab attended
Problem Statement #1:
1.
Write an uwf that will solve a system of first order ordinary differential numerically using
Euler’s method. Code for problems:
%Matlab Lab 3: Higher Order
%Enoch Crittenden
%Number 1 Code
function out = EulerODE(slope,x_initial,dx,x_final,y_initial)
x(1) = x_initial;
G(1,:) = y_initial;
n = 1;
while x(n) < x_final
G(n+1,:) = G(n,:) + slope(x(n),G(n,:))*dx;
x(n+1) = x(n) + dx;
n=n+1;
end
out = [x',G];
Name: MECH 2220 Matlab Lab 3, Fall 2020
2.
Find the analytic solution to the following third order ode. Transform the ode into a system
of three first order equations. Solve the system with the uwf developed in task one. Solve the
system with the built in function ode45. Compare the three solutions. '''
cos( ); ''(0)
1; '(0)
0; (0)
1
y
x
y
y
y
Code for problems:
%Matlab Lab 3: Higher Order
%Enoch Crittenden
clc
clear all
slope = @(x,G)[cos(x),G(1),G(2)]; %Slope form
x_initial = 0; %initial x value
x_final = pi; %final x value
dx = (pi/20); %derivative of value
IV = [1,0,-1];
fprintf(
'\t\tX\t\tY''''\t\tY''\t\tY\n'
)
Matrix = EulerODE(slope,x_initial,dx,x_final,IV) %Matrix derivation
x = Matrix(:,1);y = Matrix(:,4);
plot(x,y) %Plot
hold on
y_analytical = -sin(x)+(x.^2)/2 + x-1;
plot(x,y_analytical, 'r+'
) %Plot
%Now the ode45 method
slope2 = @(x,G) [cos(x),G(1),G(2)]';
[x,GV] = ode45(slope2,[x_initial:dx:x_final],IV);
y_ode=GV(:,3);
plot(x, y_ode,
'k.'
) %plot for graph
xlabel(
'x'
)
ylabel(
'y'
)
legend(
'Euler Method'
,
'Analytical'
,
'ode45'
)
Name: MECH 2220 Matlab Lab 3, Fall 2020
Solution for problems:
3.
Name: MECH 2220 Matlab Lab 3, Fall 2020
4.
Do problem 22.15 in your text using the function developed in #1 above. Repeat using
ode45. The motion of a damped spring-mass system (Fig. P22.15) is described by the following
ordinary differential equation:
m
d
2
x
dt
2
+
c
dx
dt
+
kx
=
0
where x
= displacement from equilibrium position (m), t
=time (s), m
= 20-kg mass, and c
=
the damping coefficient (N · s/m). The damping coefficient c
takes on three values of 5
(underdamped), 40 (critically damped), and 200 (over damped). The spring constant k
= 20
N/m. The initial velocity is zero, and the initial displacement x
= 1 m. Solve this equation
using a numerical method over the time period 0 ≤ t
≤ 15 s. Plot the displacement versus time
for each of the three values of the damping coefficient on the same plot.
Code for problems:
%Matlab Lab 3: Higher Order
%Enoch Crittenden
%Number 3 Code
clc
clear all
%Initial values for formula
%time in seconds
t_initial = 0;
t_final = 15;
dt = .05;
c = 200; %Damped value (change for each value)
k = 20; %N/m
m = 20; %kg(s)
%Slope forumula 1
slope = @(t,G)[(-c*G(1) - k*G(2))/m, G(1)];
IV = [0,1];
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
MATLAB..Hand written plz asap....i'll upvote sure
arrow_forward
MATLAB...Hand written plzzzz asap....FAST PLZZZZZZZZZZZ
arrow_forward
Given the trasnfer function
G(s)
numerator and denominator
coefficients for Matlab code should
be:
O
s³+2s+1
2s4+2s²+1'
the
num= [1 0 2 1] and den=[2 020
1]
O num=[1 2 1] and den=[2 0 2 1 1]
O
num=[1 2 1] and den=[2 2 1]
O num=[1 0 2 1] and den=[2 2 0 1]
arrow_forward
Consider the following Initial Value Problem (IVP) dy /at = -t * sin (y); y(t = 0) =1
Solve for y(t=0.5) using
a) Forward Euler method with At = 0.25. (Solve by hand)
Develop a Matlab script that solves for y (t = 5) using Forward Euler method. Use
the time step levels given below and plot t vs y in the same plot. Include the plot
with the right format (axis labels, legends, ...) in your solution sheet and include
your Matlab script in the solution as well.
i) At = 0.25
ii) At = 0.125
b) Backward Euler method with At = 0.25 (Solve by hand)
arrow_forward
What is the return type of angles function in MATLAB ?
arrow_forward
I want to run the SGP4 propagator for the ISS (ID = 25544) I got from spacetrack.org in MATLAB. I don't know where to get the inputs of the function. Where do I get the inFile and outFile that is mentioned in the following function.
% Purpose:
% This program shows how a Matlab program can call the Astrodynamic Standard libraries to propagate
% satellites to the requested time using SGP4 method.
%
% The program reads in user's input and output files. The program generates an
% ephemeris of position and velocity for each satellite read in. In addition, the program
% also generates other sets of orbital elements such as osculating Keplerian elements,
% mean Keplerian elements, latitude/longitude/height/pos, and nodal period/apogee/perigee/pos.
% Totally, the program prints results to five different output files.
%
%
% Usage: Sgp4Prop(inFile, outFile)
% inFile : File contains TLEs and 6P-Card (which controls start, stop times and step size)
% outFile : Base name for five output files
%…
arrow_forward
I am having trouble with the folloiwng MATLAB code. I am getting an error that says "unrecognized function or variable 'numericalPropogatorOptions". I have the aerospace toolbox and the aerospace blockset added. what add on do I have to download to use that function. How do I make this code work?
% Define Keplerian Elements
a = 29599.8; e = 0.0001; i = 0.9774; Omega = 1.3549; w = 0; M = 0.2645;
[RECI, VECI] = Kepler2RV(a, e, i, Omega, w, M);
initialState = [RECI * 1e3; VECI * 1e3]; % Initial position (m) and velocity (m/s)
% Define constants
mu = 3.986004418e14; % Gravitational constant (m^3/s^2)
earthRadius = 6378.1363 * 1e3; % Earth radius in meters
j2 = 1.08263e-3; % J2 perturbation coefficient
% Define propagator options
propOptions = numericalPropagatorOptions('CentralBody', 'Earth', ...
'GravitationalParameter', mu, ...
'InitialState', initialState, ...
'OutputTimeStep', 300); % Output every 300 seconds
% Add perturbations
addGravityModel(propOptions, 'Degree', 2,…
arrow_forward
Problem 2 (25 points) (CCO 3)/MatlabGrader
Develop a Matlab function that finds a root of a function g(x) starting from the given initial estimates x (-1) and x (0) with a tolerance
in function of at least OK using the secant method. Name the function mySecant using as input the anonymous function g, the
initial estimates x00 and x0, the maximum number of iterations to perform N, and the required tolerance in function epsok. As
output, the function shall return four scalar variables: the numerical solution x, its tolerance in function tolFunc, its estimated
relative error ere, and the number of iterations performed n. If the requested tolerance in function cannot be reached within
N iterations, the function shall execute Matlab's error("...") function with an appropriate error message. Other than this
potential error message, do not print out any results to screen or do any plotting within the function. You must minimize the
number of function calls g(x) required per iteration, by…
arrow_forward
If you can please take a look, I struggled with figuring out problem 2, 4, , and 6. Please let me know if you have any solutions.
arrow_forward
Please follow the instructions and the requirements according to the pictures above and I kinda need the solution quickly. The language of the code is in Matlab, thank you in advance.
arrow_forward
INSTRUCTIONS: Solve the following problem by manually applying the finite element method, following these steps:
Pre-processing:
Geometry identification.
Material properties identification.
Load identification.
Boundary condition identification.
Development of the connectivity matrix for nodes and elements.
Processing:
Calculation of local stiffness matrices.
Assembly of the global stiffness matrix.
Assembly of the global force matrix (if required).
Application of boundary conditions.
Resolution of the system of equations.
Derivation of the complete displacement vector (u).
Post-processing:
Reaction forces calculation.
Stress analysis.
Problem Statement: the truss nodes and elements (in parentheses) are already numbered. The areas (are in cm^2 ) are underlined. members are made of structural steel, modulus of elasticity is (E) of 20×10^6 N/cm^2 . the lengths are given in cm.
arrow_forward
Please help, this for Matlab the image is the first question with following 2 and 3 they go together.
2. Solving the question by using bisection.m with the stopping criterion at 1%. Report the root and # of iterations.
3. by using newton-Raphson matlab script with the stopping criterion at 0.1%. Report the root and # of iterations.
arrow_forward
Don't Use Chat GPT Will Upvote And Give Handwritten Solution Please
arrow_forward
1)
Model the following problem with integer programming. The marketing department
has been allocated a budget of $10M and would like to determine which products to develop
advertising campaigns; note: at most one campaign can be launched for each product. Their goal
is to maximize revenue for the company. Data is presented in the table below.
Product
A
BCD E F
10
7
12 8 6
Projected
Revenue ($M)
Cost ($M)
6
1 2 5 4 3
arrow_forward
Assist with MATLAB coding for part c
arrow_forward
Problem 1 (15 points) (Core Course Outcome 5)/MatlabGrader
Write a function mySecond Derivative Order 3 that calculates the second derivative d²y/dx² of a data set (x, y) with at least
third order accuracy at each data point. The data is equidistant in x with spacing h.
The function input shall be
⚫y: one-dimensional column vector of y values
⚫h: scalar value of spacing h
The function output shall be
• d2y: column vector of the same size as y containing d²y/dx²
Calculate d²y/dx² using only the following formulas that use the nomenclature of Table 8-1 and the lecture notes, but are different
from the formulas listed there:
f" (xi) 164f(xi) — 465f(xi+1) + 460ƒ (xi+2) − 170ƒ (xi+3) + 11f (xi+5) + O(h³)
=
60h2
56f(xi−1) − 105f(xi) +40f(xi+1) + 10f(xi+2) − f(x+4) + O(h³)
60h²
−5f(xi−2) +80f(xi−1) − 150f(xi) + 80f(xi+1) − 5ƒ(xi+2)
(1)
f"(xi)
=
(2)
f"(xi)
=
+0(h)
(3)
60h2
f"(xi)
-2f(x-4)+5f(xi-3)+50f(xi-1) — 110f(xi) +57f(xi+1)
=
+0(h³)
(4)
60h²
f"(xi) =
57f(x-5) 230f(xi-4) + 290 f (xi-3)-235…
arrow_forward
HW Matlab 1) Create a variable ftemp to store a temperature in degrees Fahrenheit (F). Write m-file to convert this to degrees Celsius and store the result in a variable ctemp. The conversion factor is C = (F —32) * 5/9. 2) Write m-file to generate a matrix of random integers of size 100 by 100 their values between 15 to 80. 3) Free fall of objects is given by y =5mgt? where a is the acceleration, v is the velocity, y is the distance, m is the mass of the object, g is the gravitational acceleration. Plot the distance and velocity of the object for 15 seconds after its fall from rest (y = 0). Take m = 0.2 kg.
arrow_forward
Please don't provide handwritten solution ......
arrow_forward
Use matlab to solve the question
arrow_forward
Justine Ceñidoza JC
P Comments
O Find
S Replace
BbC AABBC AaBbCcD AaBbCcD AaBbCcD AaBbCcD AaBbCcDc AaBbCcD AaBbCcD
ding 2
Title
Subtitle
Subtle Em.. Emphasis
Intense E..
Strong
Quote
Intense Q..
Dictate
Editor
A Select -
Styles
Editing
Voice
Editor
Re
4
5 . I .
B. Solve the following problem using MATLAB. Write the syntax and the MATLAB output on the space provided.
1.
Peter withdrew 10000 pesos from his bank account today. He uses 5000 to fix his car. Then, he divides the
money into 5 equal parts and gave away 4 parts and kept 1 part for himself. He took his wife to the
restaurant and spent 600 pesos on meals. The remaining cash was divided among his 5 children for their
allowance. Write a numerical expression in MATLAB syntax to represent this situation and then find how
much money Peter has now?
arrow_forward
Look up the Arduino Mega 2560. Document the steps how to work with the Arduino in Matlab and Simulink. Make a simulink program turning on the LED on the board for 10sec. Explain your program, comment on your findings and explain how to test it on the actual hardware.
arrow_forward
please write a matlab code
arrow_forward
Help me solve this using MATLAB
arrow_forward
DETAILS
CHAPMANML6 1.CQ.008.
MY NOTES
ASK YOUR TEACHER
Complete the following sentence.
Instead of typing commands directly in the Command Window, a series of commands can be placed into a file, and the entire file can be executed by typing its name in the Command
Window. Such files are called
files.
arrow_forward
Command: PLOTTERMANAGER (from the autocad file m
TO CONFIGURE A LOCAL, NONSYSTEM PLOTTER
10. PROFILES-Controls the use of profiles. A profile is a configuration you define.
367N
367N
R=1.0m
426N
426N
B.
426N
C.
The two identical sphemes having oqual weights of 367N
is placed on top of the three identic al sphere's w/ 426 N
as their reight . Compute the reaction A,B and C
arrow_forward
Read and solve carefully please write clearly and box the final answer
(remember to make the block diagram)
arrow_forward
I am trying to find a Direction Cosine Matrix (DCM) for the Euler angle body 1-2-3 sequence. I tried making my own function and using the MATLAB function, but the result is matrices that are not equal to each other. But, if I were to use the 'ZYX' sequence, I would get a matrix that is equal to the transpose of the matrix produced by my function.I mean that transpose(EA123toDCM) = E123toDCM if I changed the sequence to 'ZYX'. I never got two equal matrices. Can you fix my code so I would get two equal DCM matrices for the body 1-2-3 sequence?
Also, for the E123toDCM line, I am using the sequence 'XYZ'. Is that correct or should it be 'ZYX'? I know that that for a DCM of sequence 1-2-3 = R3(theta1)*R2(theta2)*R1(theta3). Is ZYX sequence the same as a 1-2-3 sequence?
EA = [pi/3; -pi/4; -pi/6];EA123toDCM = EA123DCM(EA)
E123toDCM = angle2dcm(EA(1,1), EA(2,1), EA(3,1), 'XYZ')
function [R] = EA123DCM(EA)
theta1 = EA(1,1); theta2 = EA(2,1); theta3 = EA(3,1); R1 =…
arrow_forward
.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Elements Of Electromagnetics
Mechanical Engineering
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Oxford University Press
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:9780134319650
Author:Russell C. Hibbeler
Publisher:PEARSON
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:9781259822674
Author:Yunus A. Cengel Dr., Michael A. Boles
Publisher:McGraw-Hill Education
Control Systems Engineering
Mechanical Engineering
ISBN:9781118170519
Author:Norman S. Nise
Publisher:WILEY
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:9781337093347
Author:Barry J. Goodno, James M. Gere
Publisher:Cengage Learning
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:9781118807330
Author:James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:WILEY
Related Questions
- MATLAB..Hand written plz asap....i'll upvote surearrow_forwardMATLAB...Hand written plzzzz asap....FAST PLZZZZZZZZZZZarrow_forwardGiven the trasnfer function G(s) numerator and denominator coefficients for Matlab code should be: O s³+2s+1 2s4+2s²+1' the num= [1 0 2 1] and den=[2 020 1] O num=[1 2 1] and den=[2 0 2 1 1] O num=[1 2 1] and den=[2 2 1] O num=[1 0 2 1] and den=[2 2 0 1]arrow_forward
- Consider the following Initial Value Problem (IVP) dy /at = -t * sin (y); y(t = 0) =1 Solve for y(t=0.5) using a) Forward Euler method with At = 0.25. (Solve by hand) Develop a Matlab script that solves for y (t = 5) using Forward Euler method. Use the time step levels given below and plot t vs y in the same plot. Include the plot with the right format (axis labels, legends, ...) in your solution sheet and include your Matlab script in the solution as well. i) At = 0.25 ii) At = 0.125 b) Backward Euler method with At = 0.25 (Solve by hand)arrow_forwardWhat is the return type of angles function in MATLAB ?arrow_forwardI want to run the SGP4 propagator for the ISS (ID = 25544) I got from spacetrack.org in MATLAB. I don't know where to get the inputs of the function. Where do I get the inFile and outFile that is mentioned in the following function. % Purpose: % This program shows how a Matlab program can call the Astrodynamic Standard libraries to propagate % satellites to the requested time using SGP4 method. % % The program reads in user's input and output files. The program generates an % ephemeris of position and velocity for each satellite read in. In addition, the program % also generates other sets of orbital elements such as osculating Keplerian elements, % mean Keplerian elements, latitude/longitude/height/pos, and nodal period/apogee/perigee/pos. % Totally, the program prints results to five different output files. % % % Usage: Sgp4Prop(inFile, outFile) % inFile : File contains TLEs and 6P-Card (which controls start, stop times and step size) % outFile : Base name for five output files %…arrow_forward
- I am having trouble with the folloiwng MATLAB code. I am getting an error that says "unrecognized function or variable 'numericalPropogatorOptions". I have the aerospace toolbox and the aerospace blockset added. what add on do I have to download to use that function. How do I make this code work? % Define Keplerian Elements a = 29599.8; e = 0.0001; i = 0.9774; Omega = 1.3549; w = 0; M = 0.2645; [RECI, VECI] = Kepler2RV(a, e, i, Omega, w, M); initialState = [RECI * 1e3; VECI * 1e3]; % Initial position (m) and velocity (m/s) % Define constants mu = 3.986004418e14; % Gravitational constant (m^3/s^2) earthRadius = 6378.1363 * 1e3; % Earth radius in meters j2 = 1.08263e-3; % J2 perturbation coefficient % Define propagator options propOptions = numericalPropagatorOptions('CentralBody', 'Earth', ... 'GravitationalParameter', mu, ... 'InitialState', initialState, ... 'OutputTimeStep', 300); % Output every 300 seconds % Add perturbations addGravityModel(propOptions, 'Degree', 2,…arrow_forwardProblem 2 (25 points) (CCO 3)/MatlabGrader Develop a Matlab function that finds a root of a function g(x) starting from the given initial estimates x (-1) and x (0) with a tolerance in function of at least OK using the secant method. Name the function mySecant using as input the anonymous function g, the initial estimates x00 and x0, the maximum number of iterations to perform N, and the required tolerance in function epsok. As output, the function shall return four scalar variables: the numerical solution x, its tolerance in function tolFunc, its estimated relative error ere, and the number of iterations performed n. If the requested tolerance in function cannot be reached within N iterations, the function shall execute Matlab's error("...") function with an appropriate error message. Other than this potential error message, do not print out any results to screen or do any plotting within the function. You must minimize the number of function calls g(x) required per iteration, by…arrow_forwardIf you can please take a look, I struggled with figuring out problem 2, 4, , and 6. Please let me know if you have any solutions.arrow_forward
- Please follow the instructions and the requirements according to the pictures above and I kinda need the solution quickly. The language of the code is in Matlab, thank you in advance.arrow_forwardINSTRUCTIONS: Solve the following problem by manually applying the finite element method, following these steps: Pre-processing: Geometry identification. Material properties identification. Load identification. Boundary condition identification. Development of the connectivity matrix for nodes and elements. Processing: Calculation of local stiffness matrices. Assembly of the global stiffness matrix. Assembly of the global force matrix (if required). Application of boundary conditions. Resolution of the system of equations. Derivation of the complete displacement vector (u). Post-processing: Reaction forces calculation. Stress analysis. Problem Statement: the truss nodes and elements (in parentheses) are already numbered. The areas (are in cm^2 ) are underlined. members are made of structural steel, modulus of elasticity is (E) of 20×10^6 N/cm^2 . the lengths are given in cm.arrow_forwardPlease help, this for Matlab the image is the first question with following 2 and 3 they go together. 2. Solving the question by using bisection.m with the stopping criterion at 1%. Report the root and # of iterations. 3. by using newton-Raphson matlab script with the stopping criterion at 0.1%. Report the root and # of iterations.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Elements Of ElectromagneticsMechanical EngineeringISBN:9780190698614Author:Sadiku, Matthew N. O.Publisher:Oxford University PressMechanics of Materials (10th Edition)Mechanical EngineeringISBN:9780134319650Author:Russell C. HibbelerPublisher:PEARSONThermodynamics: An Engineering ApproachMechanical EngineeringISBN:9781259822674Author:Yunus A. Cengel Dr., Michael A. BolesPublisher:McGraw-Hill Education
- Control Systems EngineeringMechanical EngineeringISBN:9781118170519Author:Norman S. NisePublisher:WILEYMechanics of Materials (MindTap Course List)Mechanical EngineeringISBN:9781337093347Author:Barry J. Goodno, James M. GerePublisher:Cengage LearningEngineering Mechanics: StaticsMechanical EngineeringISBN:9781118807330Author:James L. Meriam, L. G. Kraige, J. N. BoltonPublisher:WILEY
Elements Of Electromagnetics
Mechanical Engineering
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Oxford University Press
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:9780134319650
Author:Russell C. Hibbeler
Publisher:PEARSON
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:9781259822674
Author:Yunus A. Cengel Dr., Michael A. Boles
Publisher:McGraw-Hill Education
Control Systems Engineering
Mechanical Engineering
ISBN:9781118170519
Author:Norman S. Nise
Publisher:WILEY
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:9781337093347
Author:Barry J. Goodno, James M. Gere
Publisher:Cengage Learning
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:9781118807330
Author:James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:WILEY