AMATH 352
Summer Quarter, 2008

Applied Linear Algebra and Numerical Analysis



Homework #4 hints

This page has hints for Homework #4, usually in the form of backbone code. For backbone code, I've written the general structure that takes care of function declaration, initializations, and whatnot. The part you should write for yourself is indicated in capital letters.

Problem #1

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.


Problem #2

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);


Problem #3

You can do this with only one line of code, aside from the function declaration.

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])


Problem #4

For this one, it's cool if you want to assume that you're handing the function both Aech and exactly one augmented column, bech. I was thinking of something more complicated when I wrote the assignment, but decided to reel this in a little bit.

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);


Problem #5

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.