Summer 2022 Math 3607: Project 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Summer 2022 Math 3607: Project 2
Please read the following instructions carefully.
Instructions
• You are not allowed to use MATLAB commands and functions other than the ones discussed in lectures, accompanying live scripts, textbooks, and homework/practice problem solutions.
• You may be requested to explain your code to me, in which case a proper and satisfactory explanation must be provided to receive any credits on relevant parts.
• You are allowed to collaborate in a group of up to three students. In such a case, submit a single file to Gradescope. The uploader must select all group members at the time of upload. If the uploader does not select the group members, they will not receive credit.
• If any code is found to be plagiarized from the internet, you will receive a zero on the entire project and will be reported to the COAM.
• Do not carry out computations using Symbolic Math Toolbox. Any work done using sym, syms, vpa, and such will receive NO credit.
• Notation. Problems marked with are to be done by hand; those marked with are to be solved using a computer.
• Answers to analytical questions (ones marked with ) without supporting work or justifi- cation will not receive any credit.
PLU Factorization
Complete the following MATLAB function myplu .m by filling in the main loop. Inside the loop, you are allowed to use an if-statement, but a for-loop is NOT allowed. This program carries out PLU factorization of a square matrix and counts the number of row swaps. Include the function at the end of your live script.
function [L ,U ,P ,s] = myplu (A ) % MYPLU PLU factorization % Input : % A square matrix |
||
% Output : |
||
% % % |
P ,L ,U s |
permutation , unit lower triangular , and upper triangular matrices such that LU=PA number of row swaps |
%% Initialization /Preallocation n = length (A ); P = eye (n); % preallocate P L = eye (n); % preallocate L s = 0; % initialize s %% Main Loop for j = 1:n- 1 %% [FILL IN ] Pivoting % (An if-statement is allowed . ) %% [FILL IN ] Introducing Zeros Below Diagonal % (A for-loop is NOT allowed . ) end %% Clean-Up U = triu (A ); end |
Note. This is slightly different from myplu from lecture in that it has an additional output s.
Write a MATLAB function determinant2 that computes the determinant of a given matrix A using myplu function written for part (a). Include the function at the end of your live script.
Note. This is different from a previous homework problem (HW3 #5(b)) in which LU factor- ization code, mylu, was used.
Use your function and the built-in det on the matrices gallery(’cauchy’, n) for n “ 3, 4, . . . , 8, and make a table using fprintf showing n, the determinant calculated using your function determinant2, and the relative error when compared to det.
2 Least Squares for Periodic Data [25 points]
The graph below represents arterial blood pressure collected at 8 ms (milliseconds) intervals over one heart beat from an infant patient:
100
95
90
85
80
75
70
65
60
0.2
time (sec)
Denote the data points by pti, yiq for i “ 1, . . . , m. The data can be fit using a low-degree polynomial
of the form
fptq “ c1 ` c2t ` ¨ ¨ ¨ ` cntn ´ 1 , n ă m.
In the most general terms, the fitting function takes the form
fptq “ c1 f1 ptq ` ¨ ¨ ¨ ` cnfnptq,
where f1 , . . . , fn are known functions while c1 , . . . , cn are to be determined to optimize the fit to the data. This optimization can be formulated as an m ˆ n LLS problem of minimizing the 2-norm of the residual }y ´ Ac}2 , where Ai,j “ fjptiq.
(a) Download the data file pressuredata .mat and load into MATLAB using
load pressuredata
This creates two vectors t and y containing time and blood pressure data, respectively. Use them to regenerate the plot above.
(b) Fit the data to a straight line, fptq “ c1 ` c2t. Solve for the coefficients using backslash.
Superimpose the graph of the fitting line on your graph from the previous step, and compute
the 2-norm of the residual }y ´ Ac}2 , where Ai,j “ ti(j) ´ 1 is a Vandermonde-type matrix.
(c) Repeat part (b) for a quadratic and a cubic polynomial. The residual norm will get smaller in each case, but there is still a room for improvement.
(d) Exploiting the fact that the data come from a periodic phenomenon (heart beats), adapt (2) to a periodic fitting function
fptq “ c1 ` c2 cos ` c3 sin ` c4 cos ` c5 sin , where τ “ tm ´ t1 . (3)
As in the previous parts, solve for the coefficients using backslash, superimpose the graph of fptq to the plot of data points, and compute the residual norm. Comment on your observation.
2022-07-07