Question: In this exercise, you will be given an m x n matrix A. Your program has to create two bases (both are named B): one
In this exercise, you will be given an m x n matrix A. Your program has to create two bases (both are named B): one - for Col A and one - for [ ]m if Col A [ ]m , by using the columns of the given matrix A.
Your program should allow a possibility that the columns of A are not linearly independent, that is, not all columns of A will be in a basis. The set of columns of A can be shrunk to a basis for Col A by using the function shrink. Here is the code:
function B = shrink(A)
[~, pivot] = rref(A);
B = A(: , pivot);
**Create the function B = shrink(A) in MATLAB.
**Type the function shrink in your diary file
**Run each of the commands listed below (separately) on the matrix A=magic(4)
[~, pivot] = rref(A)
B = A(: , pivot)
% Place a comment in your diary file on the output for each of the commands.
**Create the function in MATLAB
function B=basis(A)
The function should start with the commands:
m=size(A,1);
A=shrink(A);
sprintf(a basis for Col A is \ n)
B=A
This part will give you as an answer a basis B for Col A.
Then, you will be using a conditional MATLAB statement within your code to check whether the matrix B, that you found, is a basis for [ ]m (or, the same, whether Col A = [ ]m). If yes, the program breaks with the message:
sprintf(a basis for R^% i is \ n, m)
(it will return your B)
If B is not a basis for [ ]m, you should expand B to a basis for [ ]m. Use the matrices B and eye(m) and the command shrink to create a new matrix D, which will be a basis for [ ]m. (A basis has to contain all vectors from B and some vectors from the matrix eye(m)). You should also write a set of commands within your code to verify whether the new matrix D is, indeed, a basis for [ ]m - the command rank will be helpful. If your code confirms that D is a basis for [ ]m, the output message should be:
sprintf(a basis for R^% i is \ n, m)
B=D;
otherwise, the program breaks with a message similar to that:
disp (What? It is not a basis!?)
**Type the function basis within the diary file.
**Run the function B=basis(A) for the following matrices:
(a) A = [1 0; 0 0 ; 0 0 ; 0 1] (b) A = [2 0 ; 4 0; 1 0; 0 0] (c) A=magic(3) (d) A= magic(6)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
