Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
25 Jun 2009 SmartInv Large sparse matrix inversion. Returns block diagonal, tridiagonal or pentadiagonal elements. Author: Rouzaud Denis Davis, Tim

There's still something wrong with this submission. I computed the exact inverse of this matrix:

http://www.cise.ufl.edu/research/sparse/matrices/HB/bcsstk28.html

and then extracted the tridiagonal entries of the inversion (entries on the diagonal, subdiagonal, and +1 diagonal).

I then computed S = smartinv(A,1,'tri'), excepting to get the same thing.

But I don't I get a matrix with zeros on the +1 and -1 diagonals, every 15 entries or so. So this revised submission is still not computing what it says it computes.

24 Jun 2009 SmartInv Large sparse matrix inversion. Returns block diagonal, tridiagonal or pentadiagonal elements. Author: Rouzaud Denis Davis, Tim

This function attempts to do the right thing when computing selected entries of the inverse, by solving a sequence of linear equations after doing an LU factorization. However, the implementation is flawed.

One suggestion: the statement [L,U,P]=lu(A) does not allow LU to permute A to improve sparsity. It would be better to use the 4-output LU, [L,U,P,Q]=lu(A), except in your case you'd need to use another name for Q since you have a Q variable already.

You would then need to use the column permutation Q in the forward/backsolve steps.

Including a "waitbar" in a function like this is not a good idea.

There seems to be a bug. The documentation says that s=smartinv(A) returns the diagonal of the inverse, but in fact I get the whole inverse back.

If I do s=smartinv(A,1), I get a diagonal matrix, but not the diagonal entries of the inverse, which is what the documentatioon said I would get. (I tried with this matrix, which is included in MATLAB):

load west0479
A=west0479;

With smartinv(A,1) or smartinv(A,1,'mono'), I should get the diagonal of inv(A) as the result, but I don't. SOmething else is returned.

Finally, the method is very slow. Computing the entire inverse takes 0.13 seconds using S=inv(A). Using S=smartinv(A) I get the same result, but it takes 15 seconds.

In the profiler, all the time is spent in this one line of code:

 Q(q0+1:q0+w,q0+1:q0+w) = insblock;

that's a very bad idea. You should never use sparse submatrix assignment, if at all possible. A better approach is to build the matrix all at once, from the blocks, using the "sparse" command.

So there appears to be at least three serious bugs in the code:
(1) does not perform according to the documentation (smartinv(A) returns inv(A), not diag(inv(A))).
(2) very slow as compared with just "inv"
(3) cannot compute the diagonal of the inverse, in spite of the fact that the documentation says it can do so. Instead it returns something else altogether.

And 2 serious drawbacks:
(1) Not really a bug, but a serious performance issue: doesn't allow for pivoting to maintain sparsity, and is thus unsuitable for large matrices.
(2) Remove the waitbar. If your function is used within other codes, the end user isn't interested in the "Inverting matrix..." message.

11 Dec 2008 fpermute Derives a matrix of all possible permutations of natural numbers 1, 2, ... , N for a given N Author: Michal Davis, Tim

A few suggestions. First and foremost, this code needs commenting. You have to look at the output matrix to figure out what matrix it's computing. This code has no comments at all. That's really the main reason I give it a rating of 3.

The second reason is that it needs to be redesigned. Wouldn't it make more sense to provide a function that returns each of the n! permutations one at a time? The matrix itself is huge. fpermute(10) returns a (10!)-by-10 matrix, about 3.6 million by 10. Surely an application doesn't need all 3.6 million permutations at the same time.

Something like:

k = 1
[p,k] = next_permutation(n,k)

which increments k. k=1 gives the first one (p=1:n), k=2 the next one, etc.

That would be a useful function. This one is limited by memory requirement to small values of n.

10 Dec 2008 Vandermonde matrix Creating matrix with terms of geometric progression in each row Author: Siqing Wu Davis, Tim

You should clarify in your help information that the matrix produced has its columns listed in the opposite order of the vander.m function in MATLAB.

Also, providing the determinant is nice, but it would be better to return the log or log10 of the determinant. That way, you can deal with determinants that are very large and very small (it's quite easy for det(A) to underflow or overflow).

Otherwise, nice work, and nicely commented. (You should have a "see also vander" line, though).

Nice use of cumprod. I'm surpised that this function is slower than vander, though.

10 Dec 2008 compare text It comapares two diferent words, and the resilts is 1 or 0. That's it Author: iokinberistain Beristain Davis, Tim

Sometimes a duplicate of an existing MATLAB function is useful, if it illustrates an algorithm for educational use, for example. This is particularly true for built-in functions like strcmp.

However, this function is so simple (and poorly commented even if you can read the language it's in), that it really serves no purpose at all. It doesn't illustrate anything useful, has fewer features than strcmp, and is slower as well. So why bother? I suggest that the author remove the file. It's really not any help, since it might mean that a MATLAB user would miss the real function (strcmp) and use this one instead.

31 Oct 2008 ftoc (v1.2) Creates a table of contents of functions contained in an m-file Author: Kenneth Eaton Davis, Tim

31 Oct 2008 ISLANDS Finds all "islands" which are 4-connected components in a matrix. Author: Matt Fig Davis, Tim

Nice work!

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com