Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

310 MATLAB\'s qr command, which we introduced in Exercise 3.2.48, can be used to

ID: 3734063 • Letter: 3

Question

310 MATLAB's qr command, which we introduced in Exercise 3.2.48, can be used to compute QR decompositions of non-square matrices. Evercise 3.3.10 (e Try out the following commands, for example n=6 m-3 A-randn (n, m) norm (eye (n)-Q' *Q) norm (A-Q*R) In the interest of convenience, MATLAB returns Q in assembled form. Write a short MATLAB script (m-file) that solves least squares problems using the qr command. (The submatrix R can be accessed by writing R (1 :m, 1 :m) or R (1 :m, :), for example.) Use your script to work parts (a) and (b) of Exercise 3.3.9. This is not the simplest way to solve least squares problems using MATLAB. Recall from Exercise 3.1.5 that the command xAlb works as well. This gives you a simple way to check your work.

Explanation / Answer

or try this...[m,n] = size(A);
[Q,R,P] = qr(A);
c = Q'*b;
% The diagonal entries of R
%|R(1,1)| >= |R(2,2)| >= |R(3,3)| >= ..
% Find the smallest integer r
%|R(r+1,r+1)| < max(size(A))*eps*|R(1,1)|
tol = max(size(A))*eps*abs(R(1,1));
r = 1;
while ( abs(R(r+1,r+1)) >= tol & r < n ); r = r+1; end
y1 = R(1:r,1:r) c(1:r);
y2 = zeros(n-r,1);
x = P*[y1;y2];

Thanks in advance....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote