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

1. Fill in the fuction N= myNull (A) to create a matrix N whose columns are the

ID: 3701478 • Letter: 1

Question

1. Fill in the fuction N= myNull (A) to create a matrix N whose columns are the homogeneous solutions (i.e. elements of the null space of A). The output of your fuction should match that of Matlab`s build-in function, N =null (A,'r'). Note that this uses the optional second input 'r'.

Hind:

function [ N ] = myNull( A )%myNull Find the null space of A

% The elimination matrix E is defined so that the entry in row i and

% column j of E*A is 0.

% Inputs:

% A - input A matrix

% Outputs:

% N - matrix whose columns are the null space vectors

% You can double check your answer by comparing it to Matlab's built-in function.

% myNull(A) should be the same as null(A, 'r')

% Also, recall the definition of the null space. If you do A * N you% should get a matrix of 0's. Think about why this is![R, c_pivot] = rref(A);

% Put A into reduced row echelon form and output the list of pivot columns

% recall, c_pivot(3) is the column containing the 3rd pivotrk = rank(R);

% rank of R (or A)[m, n] = size(R);

% size of R (or A), where m is the number of rows and n the number of columnsN = zeros(n, n-rk);

% initialize N matrix to be the appropriate sizec_free = 1:n;

% create a list of all columnsc_free(c_pivot) = [];

% remove the pivot columns from the list to get just a list of the free columns% ex. c_free(1) is the number of the first free column

%%%% YOUR CODE GOES HERE %%%%

%% For each free column, cf, find the corresponding homogeneous solution, xh

% Recall that the homogeneous solution has the following structure:

% -- The number 1 in the entry of xh corresponding to the free column

% ex. put 1 in xh(cf)

% -- The elements of the free column in R in the entries of xh corresponding to the pivot columns

% ex. put -R(i,cf) in xh(c_pivot(i))

% These xh's are stored in the columns of N

%%%% YOUR CODE ENDS HERE %%%%

end

2. Fill in the function x = myLeastSquares(A,b) to dinf the least squares solution to Ax = b. Remember that if a solution does exist, this will also be the least squares solution. The output of your function should match that of Matlab`s build - in command x = A.

Hint:

function x = myLeastSquares(A, b)

%myLeastSquares Solves the equation Ax = b when A has full column rank

% Inputs:

% A - matrix with full column rank

% b - column vector

% Outputs:

% x - column vector solving Ax = b in the least squares sense

% Check to make sure that A is full column rankif rank(A) < size(A,2)error('A is not full column rank');

%%%% YOUR CODE GOES HERE %%%%

%%%% YOUR CODE ENDS HERE %%%%

end

Even if professor gives hint...i don`t know what I have to do...please make code for those problems.

Explanation / Answer

MATLAB CODE:

Part (A)

1) function N = myNull(A)

N = rotm2tform(A);

2) clc

clear

close all;

A=[1 0 0;0 -1 0; 0 0 -1];

N=myNull(A);

disp(N)

Part (B)

1) function x = myleastsquare (A, b)

x = A b;

2) clc

clear

close all;

A=magic(3);

B=[15; 15; 15];

x=myleastsquare(A,B);

disp(x)