BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

Matlab代写 | MAE 376, Fall 2019 – Lab 4 Numerical Methods

Matlab代写 | MAE 376, Fall 2019 – Lab 4 Numerical Methods

MAE 376, Fall 2019 – Lab 4
Numerical Methods – Power Method & Finite Difference
Due 11:59 PM, November 03, 2019
Assignment
Part A: Power Method
Calculate the largest eigenvalue of the given matrix:
A =






4 3 2 1 0
3 4 3 2 1
2 3 4 3 2
1 2 3 4 3
0 1 2 3 4






(a) Download the given MATLAB code of power method powereig.m. Modify the code to output the final
iteration count. Write a script to call the given code to calculate the largest eigenvalue of the A matrix
twice, once with the tolerance set to 1.0, and then another time with the tolerance set to 0.0001. Use
disp() function to display the eigenvalues and the respective iteration count on screen.
Hint: set the initial guess of eigenvector as [1, 1, 1, 1, 1]T
.
(b) Verify the results, by using the eig() function to get the entire spectrum and then extract the largest
eigenvalue of the A matrix. Calculate the difference of the eig() outcome from those values computed
in part (a), and display the errors on the command window.
What to submit:
• powereig.m code that you downloaded and modified.
• Your own script, named as ”Lab4 A person#.m”.
Part B: 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 B person#.m”
• Your plot should be labeled properly and submitted as a single figure, ”Lab4 B person#.png”.
• Your answers for part b) and c), in a pdf file,”Lab4 B person#.pdf”.
1
Part C: 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
Figure 2: Motion Capture Lab
(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.
(b) Write a MATLAB function called ”myFD1.m” to compute the first derivatives via finite difference of
any given vector dataset, where the inputs of the function are the dataset and the step size. Write a
similar MATLAB function called ”myFD2.m” to compute the second derivatives via finite difference
of any given vector dataset.
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
2
the magnitude of acceleration via the following equations:
s =
q
V 2
x + V 2
y
, a =
q
a
2
x + a
2
y
Note that the sampling rate of the dataset is 100 Hz, therefore h = 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:
• myFD1.m function that you wrote.
• myFD2.m function that you wrote.
• The command script, named as ”Lab4 C person#.m”
• Your plot should be labeled properly and submitted as a single figure, ”Lab4 C person#.png”.
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

bestdaixie