辅导案例-MAE 376

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
MAE 376 Lab 4 (Fall 2020)
Finite Difference & Initial Value Problems
Due Wed. November 11, 2020, at midnight
Assignment
Part A: Finite Difference
1. Truncation Error
This problem explores the trade-off between the truncation error in the finite difference approximation of the
derivative and floating point round-off error incurred when using finite precision arithmetic in the computer.
(a) Write a MATLAB script that computes the first order forward difference approximation of the
derivative of cos(7x) for x = 2. Use step sizes ranging from 10−1 to 10−16. The logspace command
may be useful here. Plot the error, using a log-log scale, between your approximation and the exact
derivative for each of your step sizes.
(b) Based on your plot, what is the best step size to use for the finite difference step size?
(c) Explain the behavior you see in the graph
What to submit:
• Your final code as a single MATLAB script, ”Lab4 A1 person#.m”
• Your plot should be labeled properly and submitted as a single figure, ”Lab4 A1 person#.png”.
• Your answers for part b) and c), in a pdf file,”Lab4 A1 person#.pdf”.
2. Finite Difference Application
Finite difference is used very often in computation; this assignment is one example. We flew a UAV (Figure
1) in UB’s SMART Motion Capture Lab (Figure 2), and recorded a high-definition trajectory of the UAV
in terms of (x, y) locations measured at a certain sampling rate. From this discrete trajectory data, we can
compute the speed and acceleration of the UAV.
Figure 1: UAV
(a) Download the position data.txt file from UBlearns, and load the data into MATLAB (you can use
importdata() command). The dataset is x, y coordinates in millimeters. Convert the dataset into
meters.
1
Figure 2: Motion Capture Lab
(b) Write a MATLAB function called ”FiniDiff1st.m” to compute the first derivatives via finite difference
of any given vector dataset, where the inputs of the function are the dataset. Write a similar MATLAB
function called ”FiniDiff2nd.m” to compute the second derivatives via finite difference of the given
vector dataset. Note that the sampling rate of the dataset is 100 Hz, therefore h = δt = 0.01s.
You should setup the step size within the functions.
Hint: Consider using different finite difference methods on the first and last data points, and middle
points.
(c) Use the MATLAB functions you wrote to perform finite difference on the position data to compute
the (x, y) components of the velocity and acceleration of the UAV. Then calculate the UAV speed and
the magnitude of acceleration via the following equations:
s =

V 2x + V
2
y , a =

a2x + a
2
y
Note that the sampling rate of the dataset is 100 Hz, therefore h = δt = 0.01s.
(d) Plot the computed s and a in one figure. Find out the maximum speed and acceleration (using
MATLAB’s max() function) and display them on screen.
What to submit:
• FiniDiff1st.m function that you wrote.
• FiniDiff2nd.m function that you wrote.
• The command script, named as ”Lab4 A2 person#.m”
• Your plot should be labeled properly and submitted as a single figure, ”Lab4 A2 person#.png”.
2
Part B: Initial Value Problems (IVP)
As a sequel to the suspension system in Lab 3 (Fall 2020) with similar parameters:
MW = 55kg, MV = 1200kg, Ks = 40× 103N/m, Kt = 250× 103N/m
except this time the damping coefficient is no longer zeros, you need to consider two cases:
Case 1 : Cs2 = 15× 102Ns/m (a worn damper)
Case 2 : Cs1 = 10× 103Ns/m (a good damper)
The equations of motion are:
MvY¨v = −Ks(Yv − Yw)− Cs(Y˙v − Y˙w)
MwY¨w = Ks(Yv − Yw) + Cs(Y˙v − Y˙w)−Kt(Yw − Yr)
The initial conditions are:
Y˙v(0) = Y˙w(0) = 0
Yv(0) = Yw(0) = 0
The input function (road profile) Yr is given to be:
Yr(t) = −0.12m for t ≥ 1s
Figure 3: Suspension System on a Curb
3
Assignment
(B1) Using the known physical property that V = Y˙ , rewrite the problem as a first order system with the
unknowns Yv, Vv, Yw, Vv.
(B2) Write a MATLAB script named Lab4 B person#.m using the MATLAB built-in function ode45, to
solve the ODEs for the displacement of the masses Mv and Mw for the first 8 seconds of the journey.
In two separate figures, for the two different values of Cs (1500 v.s. 10000), plot the following: 1)
the displacement Yv, 2) displacement Yw, and 3) the road profile Yr, vs. time. Yw and Yr should
be plot on the left y-axis with limits [-0.2,0.1], and Yv should be plot on the right y-axis
with limits [-0.25, 0.05]. The region on the graph that is under the road profile shall be shaded in
grey to represent the road. Three curves must be distinguishable from each other (with different line
styles and a legend). Your name and the value for Cs should be included in the title of the figure.
Some useful information
• The MathWorks page for ode45 ( click here ),
you will see this MATLAB syntax [t,y] = ode45(odefun,tspan,y0) where odefun is a function
handle of the sytem of ODEs you need to solve.
• The MathWorks page for anonymous functions ( click here ),
you will receive more information on how to create the function handle inline with your codes.
• You can use the following line in your code to define your input function Yr, (this is an example of
anonymous function, too)
>> Yr = @(t) -0.12*(t>1 & t< 100000);
• You may use the MATLAB function fill() to specify the region for shading, an example syntax is:
>> fill(x vertices, y vertices, [0.7 0.7 0.7], ’facealpha’, 0.2 );
where x vertices and y vertices are vectors(arrays) of the x and y coordinates of the vertices of the
polygonal shape (road body).
What to submit:
• Your work for obtaining the differnetial equations ready for MATLAB, in a pdf file,”Lab4 B person#.pdf”.
Your can submit hand-written note or typed document.
• The command script, named as ”Lab4 B person#.m”
• Your plots should be labeled properly and submitted as png files, ”Lab4 B 1 person#.png”,
”Lab4 B 2 person#.png”. Your name and the value for Cs should be included in the title
of the figure.
4
Practice Problems
1. Truncation Error
Write a MATLAB script that computes the first-order accurate forward difference approximation of the
derivative of e−x for x = 0. Use step sizes ranging from 10−1 to 10−16. The logspace command may be
useful here. Using a log-log scale, plot the error, between your approximation and the exact derivative for
each of your step sizes.
2. Finite Difference On Dataset
(a) Write a MATLAB function called ”myFD.m” that computes the first derivative via finite difference
of a given vector dataset, where the inputs to the function are the dataset and the step size.
(b) Download the practice data.txt file from UBlearns, and load the data into MATLAB (importdata()).
The dataset provides x, y coordinates in meters, and the sampling frequency is 20 Hz.
(c) Perform finite difference on the position data to obtain the velocity in x and y directions.
(d) Plot the x and y direction velocity separately in a single figure.
3. IVP - Pendulum
Use ode45 to solve this following ODE
θ¨ = −ω2 sin θ − 2ζωθ˙
with initial conditions:
θ(t = 0) = 3 & θ˙(t = 0) = 0
and parameters:
ω = 10 & ζ = 0.01
Plot (θ, θ˙) vs. t for 20 seconds (try plotting with 2 y-axes), as well as θ vs. θ˙.
Bonus: animate the pendulum motion in MATLAB.
5

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468