(NOT required) In particular, for those who want some challenge, think about the following problem: Given a matrix A and vector b, decide if the linear system Ax=b is consistent or not; if yes, then deliver one solution (an arbitrary one if there are multiple ones).
Test your program on the matrix, say,
A = [1, 2, 3, 4, 0; 0, 0, 0, 2, 3; 0, 0, 0, 2, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0];
b = [1; 2; 3; 0; 0];
% fwdSubst Forward substitution to solve Ly=b by tail recursion % cmput 340, 2004 function y = fwdSubst(L,b,k) [m,n]=size(L); if ~exist('k') % If first call no k param given, but k=1 k=1; end y=b(k)/L(k,k) if k < n % Recursion step l = [zeros(k,1);L(k+1:m,k)] y = [y;fwdSubst(L,b-y*l,k+1)] end
Newsgroups: ualberta.courses.cmput.340 Subject: Re: L1 myLu(...) References:--text follows this line-- Paul Cartledge writes: > If I could get some clarification on the myLU(...) function, that would be > great. > > I believe it is wrong to assume that we will only be getting 3x3 matrices > for this lab, so I am wondering how we are to send in parameters to > myLU(). Obvioulsy your function should not just handle 3x3 matrices. Look back to the reading list for lab 1, and make sure you have read and understood the parts of the Matlab tutorial that was covered. In particular, ch 3 has the answer for how to extract properties (such as size) from a passed in matrix. Especially pay attention to table 4. Then take a look at the sample fwdSubst function supplied and see how parameters are used. > > If there's a varying number of matrices to be sent in, is there a Why would you like to pass in a varying number of matrices? > way to store the intermediate matrices we need for computation obtained > from elimMat() so that we can send them into myLU(). If you use recursion you have the benefit of a new set of intermediate variables at each call. Again study the tutorial, then the sample routine. /Martin ---------------------------------------- Newsgroups: ualberta.courses.cmput.340 Subject: Re: Leading Diag Entries of Unreduced Portions being Zero References: --text follows this line-- Don Rivers writes: > The textbook talks about the possibility of there being a leading zero in > a part we've yet to reduce. Is there an elegant way for us to interchange > rows, 1. Yes, this is essentially the same as piviting 2. You are not required to implement this in the lab, but in preparation for the lab test you should be aware of the issue from your readings (as you obvioulsy are) so you can answer oral questions. > or will all of the matrices that we will be tested on not have > leading zeros in parts that we are working on? On a test matrix with a leading 0 you will have to point out why your code doesn't handle it, identify the problem, and the particular place in the code. /Martin ------------------------------------ Newsgroups: ualberta.courses.cmput.340 Subject: Re: NxN, or MxN? References: --text follows this line-- Don Rivers writes: > I don't know if this has been answered, but are only going to be tested on > Square Matrices, or on nonSquares as well? Not required to handle non-square matrices. > > I notice that matlab's lu() complains if you pass it a nonsquare matrix, > so do we have a similar requirement? Actually, it is possible to compute an L U factorization through elimination even for an mxn matrix. It is just not implemented in matlab 5 (but was fixed in matlab 6). /Martin