AMATH 352
Summer Quarter, 2008
function solvability = issolvable(Aech, bech) % Record the number of rows in Aech. r = size(Aech,1); % Record the number of columns in Aech. d = size(Aech,2); % WRITE CODE THAT WILL DETERMINE WHETHER THERE'S A ROW OF ZEROS % IN AECH THAT'S ADJACENT TO SOMETHING NONZERO IN BECH. % IF THERE IS, SET SOLVABILITY=0, FOR NOT SOLVABLE. % OTHERWISE, SET SOLVABILITY=1, FOR SOLVABLE.
function [pivotvars, freevars] = pivotfree(Aech) % Record the dimensions of Aech. r = size(Aech,1); d = size(Aech,2); % Initialize a vector with one zero for each column of Aech. P = zeros(1,d); % WRITE CODE THAT WILL PLACE A 1 IN EACH POSITION OF P % THAT CORRESPONDS TO ONE OF THE PIVOT VARIABLES. % Take each position in P with a 1, and store it in pivotvars. pivotvars = find(P == 1); % Take each position in P with a 0, and store it in freevars. freevars = find(P == 0);
It's handy to know how to pull specific columns out of a matrix. Try this:
>> A = rand(3,5)creates a random matrix with 3 rows and 5 columns. Then
>> indices = [2 3 5]; >> A(:, indices)pulls out columns 2, 3, and 5. You don't actually have to use the variable indices, though. You could just as easily say
>> A(:, [2 3 5])
function [Arech, brech] = jordanelim(Aech, bech, pivotvars) % Record the number of columns in Aech. d = size(Aech, 2); % Store Aech and bech in an augmented matrix. aug = [Aech bech]; % WRITE CODE THAT USES PIVOTING TO CANCEL ALL ELEMENTS % ABOVE EACH OF THE LEADING 1'S THAT CORRESPOND TO % PIVOT VARIABLES. % Break the augmented matrix back into its two parts. % Store these as Arech and brech, the outputs of % this function. Arech = aug(:, 1:d); brech = aug(:, end);
function N = findnull(Aech, pivotvars, freevars) % Record the number of columns in Aech. d = size(Aech,2); % Initialize a matrix with one column of zeros for each % free variable. This will record the vectors in the null % space. N = zeros(d, length(freevars)); % Remove all excess zero rows from Aech. Aech = Aech(1:length(pivotvars), :); % Store the columns of Aech that correspond only to the % pivot variables. Aechpivot = Aech(:, pivotvars); % WRITE CODE THAT CALCULATES ONE VECTOR IN THE NULL SPACE, % LIKE IN LECTURE #14. STORE THESE IN THE COLUMNS OF N % AS YOU GO ALONG.