Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How do I do this in Matlab? Determine whether it is a case when the vector be Col A. (You could use a MATLAB command
How do I do this in Matlab?
Determine whether it is a case when the vector be Col A. (You could use a MATLAB command rank.) If be Col A, the program should give outputs (without any computations!): the vector p, the corresponding vector z, and a message "b is in the Col A". After that, the program terminates. Part II. Orthogonal Projections & Least-Squares Solutions Exercise In this exercise, you will write a MATLAB function [p, z proi(A.b) which computes the projection of b onto the Column Space of an mxn matrix A. Your program should allow a possibility that the columns of A are not lincarly independent. In order for the algorithm to work, you will need to create a basis for Col A *A basis can be produced with the function shrink that you should create in MATLAB Here is the code: If b Col A, proceed to the next step (1) Determine whether it is a case when b is orthogonal to Col A. If it is the case, the program should have outputs (without any computations!): the vector p, the corresponding vector z, and a message "b is orthogonal to Col A". After that, the program terminates. Ifb is not orthogonal to Col A, proceed to the next part: (2) Find the solution of the normal equations i (see above)-please use the backslash operator, L within your code. Then calculate vector p Ai. The vector z b-p. function B shrink(A) format compact, B- AG pivot): Also, to save a space in your file, all input vectors must be row vectors and you can use a MATLAB command transpose to make the adjustments for the outputs to be row vectors as well. Note: the MATLAB command transpose(X) is the same as X One more command should be written to check whether the vector p is, indeed, orthogonal to the vector z-b-p (check whether the inner product of thesc vectors is zero). (For purpose of this program, we assume that a number is zero if its absolute value is less than 107). If your code confirms that plz, please display a message: "Yes, p and z are orthogonal! code?" Great Job!" Otherwise, the message should be something like: "Oops! Is there a bug in my Recall: The vector p is the orthogonal projection of a vector bg Col A onto Col A, when the columns of A are linearly independent, if and only if p Ai, where i is the least-squares solution of Ax b, or equivalently, the unique solution of the normal equations INSTRUCTIIONS *Type the functions shrink and proj within your diary file. Also, if p is the orthogonal projection of a vector b onto Col A, then the vector b can be written as b-p+z, where z is the unique vector orthogonal to Col A *Run the function [p, 2proj(A.b) on the following matrices A and vectors b. Notice please that some of the matrices are created in a few steps. Your function proji(A.b) should begin with Please input the matrices exactly in the following formats (notice that somc outputs below are format compact, A-shrink(A); b transpose(b) (a) A-magic(6); A-A(:,1: 4), b- (1:6) (b) A-magic(6), E-eye(6); b E( 6,) (c) A magic4), b- (1:5) (d) A magicS), b- rand(1,5) (e) A-ones6); A()-1:36, b 1,0,1,0,1,0] () A- ones(6); AC:)-1: 36 A- null(Ar), b -ones(1,6) (Remember, the input vector b must be a row vector, therefore, we need to convert it into a column vector (by transposing) if you need to find the solution of the normal equations). Then, the program has to check if the input vector b has exactly mentries, where m is the number of columns in A. Ifit doesn't, the program breaks with a message: "No solution: dimensions of A and b disagree" and retums empty vectors p and z. You could type the following lines in your code The Exact and Least-Squares Solutions Orthonormal Basis An mxn matrix U has orthonormal colum ns if and only if UrU =1", where 1, is an nxn identity matrix Ifan mxn matrix U has orthonomal columns and W-Col U, then, for any vector be disp(No solution: dimensions of A and b disagree') returm If matrix U is an orthogonal matrix, that is, U is an nxn matrix with orthonormal columns, then I) U U (2) W (3) UU-U'U-L; (4) b-proj b-b If b has exactly m components, proceed to the next stcpStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started