Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
23 Sep 2009 Padefit Rational polynomial fitting Author: Paul Godfrey Erres, Seis

Thank you very much for this nice function which works perfectly

03 Sep 2009 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey togi, hendra

i have a project (Robust DWT-SVD Domain Image Watermarking:
Embedding Data in All Frequencies).
i use DWT, decompose the cover image A into 4 subbands:
LL, HL, LH, and HH.
can you tell me how to apply svd to each subband image…
the program uses matlab. thx

05 Jun 2009 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey Grine, Slimane

Thanks. Very useful!

18 Jan 2009 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey Deepak

Its so lovely to see this function on the first search.
Extremely handy.
Please post some references as well for the theory.

13 Jan 2009 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey Lei

Could anybody tell me how to evaluate the time required by the SVD. Please kindly note the svd.m called directly by the workspace is a built-in function, which is much faster than the svd.m available on the Matlab website. So which one is more suitable to evaluate the required time?

Actually, I am trying to compare a new algorithm with the SVD in computational cost or time. I suppose the built-in SVD function might be faster than the source-code SVD function. Could anybody help me? Thanks a lot for your kindly helps in advance! My email address is huanglei8rsp@yahoo.com.cn.

23 May 2008 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey ahmed, ben talbe

01 May 2008 fftd.m A dimensionless Discrete Fourier Transform program. Author: Paul Godfrey Ocampo, Jonathan

I need a function that can makes symbolic fourier transform

31 Jan 2008 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Davis, Tim

The determinant of a matrix can easily be extremely large or extremely small for a modest-sized matrix, leading to numeric underflow or overflow. I would suggest an option that sums the log of the diagonal of R, instead of prod(diag(R)). I do the same trick in umfpack with [d e] = umfpack(A,'det') which returns the determinant as d*10^e.

The function det in MATLAB has the same underflow/overflow problem, but det(Q) I think is +1 or -1 so perhaps it's not a issue.

Seems like there should be a better way of computing det(Q) than with det(Q), since Q is an orthogonal matrix and has such nice properties.

Just a suggestion.

24 Jan 2008 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Responsibly, Comment

Mr. Godfrey I thank you. There are a few bullies running around on the Matlab exchange randomly attacking authors. Most authors just ignore them, but I fear some may be turned away from the site because of them. So thank you for sticking up for yourself and demonstrating how shrill, petty, and useless their comments usually are. These people seem to want published, polished, ready-for-sale code. The truth is matlab isn't for hardcore programmers. It is for people who want a TOOL to solve a particular PROBLEM THEY need solved, not a product development suite. So most programs found on the file exchange will be imperfect and have a very limited scope.

I'm amazed by the sense of entitlement these commenters display. Contributors have, out of the goodness of their hearts, given free code to the world. It is FREE. If they don't like it, they need not use it.

Thanks again Mr. Godfrey.
I will give Mr. D'Errico credit for engaging you in the discussion, regardless of the tone. I am also very impressed that he changed is rating after some discussion.
Jos x@y.z however seems to have a habit of being the first and least knowledgable commenter on many programs. He also rarely returns to apologize or retract his statements when he is shown to be very wrong. His rediculous snap judgments are exactly the type of thing my whole comment is about.

20 Dec 2007 fftd.m A dimensionless Discrete Fourier Transform program. Author: Paul Godfrey hasnoend, wezza

24 Jul 2007 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey A, Silvia

This program satisfy
A * Inv(A) = I
with Inv(A) = Adj(A)/det(A)
When I tried contrary Inv(A)*A ~= I, the result isn't I anymore.
I think this situation should satisfy both condition.

01 Apr 2007 ccom Canonical transforms Perform control state space canonical transforms Author: Paul Godfrey rabah, BOUFASSA

28 Mar 2007 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey Lakshmipathi, Sondur

My sincere thanks to the author. Very useful method. I compared the result with matlab inbuilt function on SVD, both match well. I had done in my application QR decomposition, I thought of reusing it for SVD computation, this helped me a lot. Good work.

18 Jan 2007 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey fiser, ugl

nice work and easy touse

thanx lot

08 Nov 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Regarding the comments of John D'Errico:
"So why should anyone bother to use your code, when they can copy a better version out of this review?"
Because it's publicly available as a submitted .m file.
Why don't you go ahead and submit your own version?
Won't that make it easy for all Matlab users to find and use?

"Can you show ANY reason why the svd version is clearly the best answer as you claim?"
I never claimed that the SVD algorithm was the best one to use for computing DETT.
I claimed that the SVD algorithm is the best one to use when "solving" a singular set of equations.
It is common knowledge that the SVD gives you the Least squares solution for over determined systems, the exact answer for full rank systems, and the minimum norm answer for under determined systems.

Why did you take a discussion about solutions of linear systems and twist it into a claim about the best algorithm to use?

IMHO, you appear to want to try and win some kind of argument or contest of some sort.
Your postings have been in a rather belligerent and "in your face" style.
I prefer a more thought based rational discussion instead.

"dett, based on the svd is slower than it needs to be"
Ok, good for you.

"nicely on sparse matrices. Can that be said for dett?"
Well, I never claimed that it was designed for sparse matrices.

"Error in ==> dett at 20"
So, go ahead and submit it.

"So, no, I don't consider a poor implementation of any tool to be worth an excellent rating"
Ok, but I never asked you to rate it.
Why do you think that I care?

"Not when a superior one is so trivial to write."
Sigh.
You really want to win something here don't you?
I can't help but ask:
Before you saw this submission, how did you calculate the Determinant and Adjoint of non-square matrices?

02 Nov 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey D'Errico, John

So why should anyone bother to use your code, when they can copy a better version out of this review? Can you show ANY reason why the svd version is clearly the best answer as you claim?

function [d] = dett2(A)
%Dett2 Determinant of any sized matrix
%
%usage: d = dett2(A)
%
%see also: Det, Cond, Eig, SVD

[r,c]=size(A);
if r>=c
  [Q,R] = qr(A);
else
  [Q,R] = qr(A');
end
if r==1 | c==1
   R=R(1);
else
   R=prod(diag(R));
end
d=det(Q)*R;

Comparison:

>> A = rand(500,200);
>> tic,p=dett(A);toc
Elapsed time is 1.351050 seconds.
>> tic,p=dett2(A);toc
Elapsed time is 0.688662 seconds.

So, dett, based on the svd is slower than it needs to be.
Is it more capable? Dett2, as I've just supplied, works
nicely on sparse matrices. Can that be said for dett?

>> A = sprand(500,200,.1);
>> tic,p=dett2(A);toc
Elapsed time is 3.930455 seconds.

>> tic,p=dett(A);toc
??? Error using ==> svd
Use svds for sparse singular values and vectors.

Error in ==> dett at 20
[u,s,v]=svd(A);

So, no, I don't consider a poor implementation of any tool to be worth an excellent rating. Not when a superior one is so trivial to write.

01 Nov 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Regarding the comments of John D'Errico:
"...WHEN A is nonsingular. Obviously this fails for singular arguments."
And that "failure" is the correct answer for a singular matrix.
For any matrix,(square or non-square), with one or more singular values equal to 0, no inverse (left, unique, or right) is going to exist.
In that case we resort to the SVD to provide the "best" answer under those circumstances.

"Were there other uses proposed for this extension of dett, I might up my rating further..."
Well, some of us consider a consistant extended definition of Det() to be "use" enough... ;)

24 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey D'Errico, John

Cogent arguments by Paul in favor of dett. If one has the goal of an extension of the determinant in a way that is consistent with the pseudoinverse, then adj(A)/dett(A) succeeds, WHEN A is nonsingular. Obviously this fails for singular arguments.

Were there other uses proposed for this extension of dett, I might up my rating further. For example, det is often used to compute the volume of an n-d simplex. Is there a similar extension for dett? (Consider a simplex that lives in a planar subset of a higher dimensional space. Dett should indeed apply here.) Another use for the determinant is as applied to the Jacobian in variable transformations. Is dett consistent as an extension there?

The new version of adj is up there now, so I could test them both further. I was wondering if LU would offer a more efficient approach to its computation. This would work if a standard property of the determinant also applied:

A = triu(rand(3,4));
dett(A) ~= prod(diag(A))

An LU based dett would allow it to apply to sparse matrices - which might offer an improvement over pinv.

So, along those lines, why not consider a QR version of dett? QR applies to sparse systems. It is numerically well behaved, especially if the column pivoted form is used. It will be faster than the svd solution. The only flaw is a QR based dett will work only for non-square systems with more rows than columns. So when there are more columns than rows, apply the QR to the transpose.

[n,m] = size(A);
if n<m
  A = A';
end
[Q,R] = qr(A);
D = det(Q)*prod(diag(R));

This can be hacked easily enough to use a column pivoted QR, though the column pivoted version does not work for sparse problems. You would need to revert to the simpler code above when sparse.

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Regarding the comments of John D'Errico:
A right or left pseudo-inverse MAY exist. But this "determinant" seems to tell you nothing that rank or cond will not say better.
<I agree. But the purpose of my Adj() and Dett() programs is to provide meaningful values for non-square matrices.>

If your goal is merely to compute a pseudo-inverse, then use pinv - a far faster solution than one based on the adjoint.
<No, my goal is to extend the definition in a meaningfull manner>

Looking more closely at the author's claim, I'll note that adj fails when applied to non-square matrices. I just download the latest version of adj.
<Sigh, you don't have the latest version.
Is your version dated April 1998 or October 2006?>

Try this:
adj(rand(5,3))
<Works fine with the latest version.
Give the Mathworks people a day or to to make the latest version available.>

This does not even touch the question of complex (particularly self adjoint) matrices as brought up by a review of adj.
<It works fine for complex matrices as well.
There are multiple definitions of Adj().
My definition is based on Inv(A) = Adj(A)/Det(A)
as given on page 169 of "Applied Linear Algebra, 3rd edition" by B. Noble and J. Daniel

For square matrices, this code is also far slower than Matlab's existing det function anyway.
<True. And is also true the Matlab's own Det() function doesn't handle non-square matrices like mine does>

So at the very least users should be cautioned away from using this code on square systems.
<True>

Since apparently non-square systems are not handled as the author claims,
<Try again in a day or two.>

I see no use at all,
<Other than providing a meaningful extension of the definition of Adj() and Det()>

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Regarding some comments by Jos x@y.z:
1) The adjugate is also only defined for square matrices.
The real question to ask is "Can an Adjugate matrix be defined in a meaningful manner for non-square matrices?"
For many non-square matrices the Matlab Pinv command can generate a left, right, or true inverse for the matrix.
The matrix inverse is typically defined as Adj(A)/det(A).
So the problem then becomes one of finding a useful value for Adj(A) and det(A) when A is non-square that "matches" in Pinv(A) in some sense.
My Adj(A) and dett(A) programs do exactly that.

2) orth(rand(3,2)) produces three rows that are NOT linearly independent, e.g., its rank is 2.
And that tells me that a left inverse exists but not a right inverse.
The left inverse should generare Eye(2)
and the right inverse would (if it existed) generate Eye(3).
Therefore, that inverse should be Adj(A)/dett(A).
Or, in terms of dett(A), Adj(A)*A = I*dett(A)
To see more clearly what the value of dett(A) should be try this:
A=rand(3,2)
B=Adj(A)
B*A
eye(2)*dett(A)

They are equal, as expected.

I think that the real problem here is that most Linear ALgebra books don't completely cover the Adj() function.
The reason for that is, probably, that the Adj() was computed using co-factors and such which is horribly inefficient.
I don't think many people looked at computing the Adj() using the SVD.
Try pinv(A), Adj(A)/dett(A)

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey x@y.z, Jos

1) The adjugate is also only defined for square matrices.
2) orth(rand(3,2)) produces three rows that are NOT linearly independent, e.g., its rank is 2.

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey D'Errico, John

A right or left pseudo-inverse MAY exist. But this "determinant" seems to tell you nothing that rank or cond will not say better. (NEVER use any variety of determinant to identify the singularity status of a matrix.)

If your goal is merely to compute a pseudo-inverse, then use pinv - a far faster solution than one based on the adjoint.

Looking more closely at the author's claim, I'll note that adj fails when applied to non-square matrices. I just download the latest version of adj. Try this:

adj(rand(5,3))
??? Error using ==> eig
Matrix must be square.

Error in ==> adj at 16
ce = poly(eig(A));

The other way fails too:

adj(rand(3,5))
??? Error using ==> eig
Matrix must be square.

Error in ==> adj at 16
ce = poly(eig(A));

This does not even touch the question of complex (particularly self adjoint) matrices as brought up by a review of adj. I've not checked that issue.

For square matrices, this code is also far slower than Matlab's existing det function anyway. So at the very least users should be cautioned away from using this code on square systems. Since apparently non-square systems are not handled as the author claims, I see no use at all, unless you wish to compute the pseudo-inverse of a scalar.

Just use pinv for your pseudo-inverses. Pinv will work for rank deficient problems too, whereas this code will fail due to the singularity.

23 Oct 2006 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey Godfrey, Paul

To Luis T. (ltirado@gmail.com):
Your professor is referring to one of the other definitions of "Adjoint"

This program was written to satisfy
A * Inv(A) = I
with Inv(A) = Adj(A)/det(A)
So, for your example, Adj(A) = [0 -j; j 0] ans det(A) = -1
We have A*Adj(A)/det(A) = [1 0; 0 1] = I, as required.

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Regarding the comment of Jos x@y.z
"For non-square matrices, there are always rows/columns that are not indepenent of other rows/columns."
Not true at all. Consider orth(rand(3,2))
You have 2 orthogonal vectors in a non-square matrix.

23 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey Godfrey, Paul

A few comments by the author...

To Scott Miller: Matlab's own SVD should always be, for many reasons, the program of first choice most SVD needs.
The purpose of this program was to demonstrate a very simple way to compute the SVD that was probably not well known.
To John D'Errico: Your first set of comments appear to be based on the assumption that this code is intended to compute with Matlab's own SVD code for all user applications. It is not.
Upon typing 'Help svdsim; the used clearly sees "A simple program that demonstrates..."
As such, I did not, originally, bother with a robust exit scheme since the program intent was algorithmic in nature and not efficiency oriented. However, I have updated the program to add a more sophiticated exit mechanism.
For your second comment and for the comments of Carlos López: The program could certainly be used to refine an existing SVD solution.
The required code would be trivial to add.
Also, QR decomposition routines (MGS) are easy to write by almost any programmer. However, an SVD routine is a more daunting task and is usually sent to a canned library routine.
This program provides an easy to implement algorithm that can be used whenever a more sophisticated math library is not available.

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey Godfrey, Paul

Not nonsense at all.

Consider that for non-square matrices, a left or right inverse may exist.
The inverse may be defined as Adjoint(A)/Det(A)
This program computes a meaningful value for Det(A) consistant with that definition.
Taker a look at the Adj.m program to put all the pieces together.

23 Oct 2006 Dett Computes the determinant of non-square matrices. Author: Paul Godfrey x@y.z, Jos

This is mathematical nonsense.
For non-square matrices, there are always rows/columns that are not indepenent of other rows/columns. So, by definition, the determinant of non-square matrices should be zero!
That is why textbooks always say that the determinant is only defined for square matrices.

20 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey López, Carlos

I consider seriously your comments, John. Thus, I will pose a different but related question to the readers: Is there a better algorithm to improve an estimate of the SVD than the one provided by this submission?
Regards
Carlos

20 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey D'Errico, John

While future higher precision computations might allow refinement using the scheme in this code, if higher precision is available in the future, then the svd code itself would far more efficiently call a higher precision version of svd at relatively little cost in time. An expensive refinement scheme would seem to be of little value.

19 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey López, Carlos

Aside for dealing with sparse matrix, there might be another application for this code: improving an already available approximation of the real solution. Apparently svd does not take advantage of any first guess.
I suggest something like
[U,V,S]=svdsim(A,U0,V0,S0);
To test this, you can use something like
[U0,V0,S0]=svd(single(A));
to have an initial value, and later invoke the svdsim routine. A comparison might be made with the standard svd.
I foresee an application for higher-than-double precision calculations within matlab. In such case, the output of the standard svd can be improved to the required precision with a routine similar to svdsim.
Regards
Carlos

19 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey D'Errico, John

This would appear to have NO advantages over svd. It will be immensely slower than svd. One exception - in theory, svdsim will work on sparse matrices. However, svdsim is so slow that even here you are far better off converting your matrix to a full one, then calling svd. For example:

>> X = sprand(50,50,.01);
>> tic,[u,s,v]= svdsim(X);toc
Elapsed time is 4.720246 seconds.
>> tic,[u,s,v]= svd(full(X));toc
Elapsed time is 0.002718 seconds.

Note, this gets far worse if X is less sparse.

>> X = sprand(50,50,.1);
>> tic,[u,s,v]= svdsim(X);toc
Elapsed time is 41.527362 seconds.
>> tic,[u,s,v]= svd(full(X));toc
Elapsed time is 0.012801 seconds.

Another problem with this code is the lack of a convergence tolerance. It merely loops an arbitrary number of times, then quits.

So don't use this code to compute the svd. Just use svd.

This leaves only one purpose - an expository one. It does that reasonably well, but even there the lack of any convergence criterion suggests a low rating. Good expository code might also suggest why there is no sort at the end on the singular values, and provide a reference for the student to read further on methods to compute the SVD.

I'll raise my rating with improvements in the exposition and code.

18 Oct 2006 Simple SVD SVD computation using QR decomposition Author: Paul Godfrey Miller, Scott

What are the advantages and disadvantages of using this routine over the function svd included in MATLAB?

Scott

18 Oct 2006 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey T., Luis

Does this take into account complex matrices?

In my graduate linear systems analysis course today, our professor today discussed that if a matrix is self-adjoint, then adj(T) = T.

For a real matrix, this means it must be symmetric, and for a complex matrix, it means that it must be hermitian.

For the hermitian and self-adjoint matrix:
T=[0,j;-j,0]

adj(T) should be equal to T

Using this program, it comes out to be conj(T). I believe that should not be the case, unless I'm totally mistaken.

03 Aug 2006 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey divan, muhamet

26 May 2006 erfz Compute the error function for complex inputs. Author: Paul Godfrey Davis, Tom

some very nice coding here

22 May 2006 Padefit Rational polynomial fitting Author: Paul Godfrey Getreuer, Pascal

Finally, an easy program for Padé approximation! Works great, elegantly written. Note: For users without the symbolics toolbox, just remove the debug code and the code after the return statement and it works.

20 May 2006 Padefit Rational polynomial fitting Author: Paul Godfrey Pastushenko, Vassili

Sure I should prefer a program which would suggest some optimal values of kn and kd. I hope to survive up to appearance of such a version in FEX, at least for kd=0.

20 May 2006 Psi Compute the psi or digamma function. Author: Paul Godfrey Borghi, Matteo

19 May 2006 Padefit Rational polynomial fitting Author: Paul Godfrey Kleder, Michael

Very nice. Thanks.

10 Apr 2006 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey Borghi, Matteo

22 Mar 2006 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey Fruehwirth, Rudi

Very useful!

31 Jan 2006 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey Davidson, Bill

Thank you. Excellent. It is a handy function to have around.

24 Jan 2006 Special Functions math library Collection of Special Functions programs. Author: Paul Godfrey andjez@gazeta.pl, andrzej

09 Nov 2005 Gamma Compute a very accurate Gamma function over the entire complex plane. Author: Paul Godfrey de chatellus, hugues

03 Nov 2005 Psi Compute the psi or digamma function. Author: Paul Godfrey Monteiro, Marcus

Implementation well done and I used to converto to another language.

23 Oct 2005 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey ., .

19 Oct 2005 Special Functions math library Collection of Special Functions programs. Author: Paul Godfrey Selins, Bart

This is exactly wat I needed, works perfect

18 May 2005 Special Functions math library Collection of Special Functions programs. Author: Paul Godfrey Ramirez, Jaime

Really useful, includes functions that are not easy to find somewhere else

23 Feb 2005 adj.m Finds the adjoint of any rectangular matrix Author: Paul Godfrey Taillon, Jason

Works very well

13 Jan 2005 Special Functions math library Collection of Special Functions programs. Author: Paul Godfrey Abdallah, Amine

 

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