Rank: 6 based on 4461 downloads (last 30 days) and 52 files submitted

John D'Errico


Personal Profile:

Mainly retired from Eastman Kodak. (Of course, Kodak itself is now semi-retired. I don't think I had any influence in that.) I still write MATLAB code as I find something interesting, but I DON'T answer your questions, and I do NOT do homework. Your homework is YOUR problem, not mine. Do NOT e-mail me with your homework problems or student projects. When I'm not doing something with MATLAB, you might find me playing bridge.


Watch this Author's files


Files Posted by John D'Errico View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
16 Oct 2014 movingstd(x,k,windowmode) A (fast) windowed std on a time series Author: John D'Errico movingavg, standard deviation, std, window, filter 152 18
  • 4.75
4.8 | 12 ratings
14 Oct 2014 HPF - a big decimal class High precision floating point arithmetic, a new class written in MATLAB Author: John D'Errico hpf, multiple precision, big decimal, floating point, arithmetic, mathematics 84 20
  • 5.0
5.0 | 9 ratings
23 May 2014 Screenshot A suite of minimal bounding objects Suite of tools to compute minimal bounding circles, rectangles, triangles, spheres, incircles, etc. Author: John D'Errico miminum, bound, bounding, circle, rectangle, triangle 95 18
  • 4.71429
4.7 | 7 ratings
29 Apr 2014 polyfitn Polynomial modeling in 1 or n dimensions Author: John D'Errico polyfit, modeling, regression, linear regression, approximation, function 391 43
  • 4.96
5.0 | 25 ratings
29 Apr 2014 Screenshot SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico spline, splines, cubic, hermite, breaks, knots 204 103
  • 5.0
5.0 | 52 ratings
Comments and Ratings by John D'Errico View all
Updated File Comments Rating
19 Nov 2014 Making given matrix singular Making the given matrix singular by adding a matrix with multiplier. Author: Feng Cheng Chang

I never said you could use norm to test for singularity of a matrix!

I did say you could use rank, cond, or svd to determine that status, AND be far ahead of the use of det.

I already showed how poor det is, using several examples. It is simply a terrible idea to use that tool. Yes, I know that your teacher told you about it, or some book you read. The fact is, they probably learned it from someone before them, and they are just propagating the use of a terrible tool for the purpose.

When you use det in floating point arithmetic, is is simply a bad thing to do. This is what those people who taught you did not understand. They thought that because something is valid in a mathematical sense, that it is a good thing to do on a computer. Sorry, but computer programming is NOT mathematics. Floating point arithmetic is a different animal, and is only vaguely related to mathematics.

The simple answer is to just use rank. If the matrix is less than full rank, then it is singular.

If you want, you can use cond. Large condition numbers are bad. A condition number that is roughly 1/eps indicates singularity. The problem with cond is it takes some (minor) judgment on your part. How close does a condition number need to be to 1/eps for the matrix to be numerically singular? At the same time, use of cond gives you some information that rank does not, since it tells you how close to singularity is the matrix.

And of course, you can use svd, which tells you more yet. Since the condition number is the ratio of the largest to smallest singular values, you can see if the matrix is singular easily enough. But several singular values that are relatively zero compared to the largest tells you much about the matrix too.

Again, rank is simplest here, FAR better than det. Avoid det, like you would avoid the bubonic plague. I showed several cases where det simply fails to yield an answer that is even close to truth.

16 Nov 2014 Making given matrix singular Making the given matrix singular by adding a matrix with multiplier. Author: Feng Cheng Chang

Why do people use det to determine if a matrix is singular? For example, in this code, we see the terribly poor code...

DetA = det(A);
if abs(DetA) < 1.e-8, disp("*** The original matrix [A] is singular ! ***"), return; end;

So why is it poor?

Consider the matrix

A = eye(10);

Clearly, it is not singular. How about the related matrix B though?

B = 0.1*A;

Does everyone agree that B is not singular? Yet see that D has a small determinant!

ans =

ans =

Or, how about this simple matrix?

A = randn(100,99);
A(:,100) = A(:,99) + eps;

It seems pretty clear that A is singular. But does det tell us that?

ans =

Well, if the test in the code by this author is any indication, that matrix is definitely NOT singular! Of course, we can use the same scaling trick to decide it is singular.

ans =

The point is, det is arguably a terrible way to determine if a matrix is singular!

Instead, use rank, or cond or svd to determine that characteristic of a matrix. Of course, cond and svd tell you more about the matrix, but you also need to understand how to use those tools to infer if the matrix is singular.

The rest of the code itself is also not terribly good. It is a function, yet it uses input to pass in the matrix! I shiver at the idea, as this is a terrible user interface. A function has arguments. Learn to use them!

As I look at the code itself, I see that it will fail to execute. It fails to use valid MATLAB syntax. Here is the line I saw:

disp("*** The original matrix [A] is singular ! ***")

See that MATLAB strings are delimited by single quotes, i.e.: '

Thus we define a string as 'This is a string'

However, "This is not a string"

Next, the code says that it can be used to modify a single element, a row, a column, or the entire array, yet no explanation of how one would do any of those things. (Yes, I know after reading through the code, one might infer that these things are controlled by the vectors r and c. However, unless you understand the linear algebra involved, then one would never know what is meant there.)

An interesting question is if the perturbation generated is a minimum norm perturbation. The answer is it is not so at all.

For example, if I generate a random 5x5 matrix A as

A = rand(5);

It would seem that to choose a modification of the matrix A that allows all elements to change, then I want to specify r and c as:

r = ones(1,5);
c = ones(1,5);

Then the matrix perturbation provided by this code is given in the code as D. How much of a perturbation is D?

ans =

It is pretty big actually. Instead, we can compare it to a minimum norm perturbation based on the SVD.

n = size(A,1);
[U,S,V] = svd(A,0);
Dmin = U(:,n)*S(n,n)*V(:,n)';

ans =

And in fact the svd based solution has a larger condition number here, so it is closer to being numerically singular than that provided by the code from the author.

cond(A - Dmin)
ans =

cond(A - D)
ans =

When I originally looked at this code, I was hoping to see some nice, well written, numerically stable code to solve a moderately interesting problem. I did not find that here. I'm sorry, but there are too many problems to call this code good given all of these issues.

11 Nov 2014 Inverse Tangent Doubt Doubt related Inverse Tangent Author: JANAK TRIVEDI

This is not where you post your questions.

10 Nov 2014 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico


08 Nov 2014 nearestSPD Finding the nearest positive definite matrix Author: John D'Errico

I actually nudge the matrix just a bit at the very end if necessary. The code should ensure that chol applied to the result will always yield a valid factorization, and that is essentially the test in MATLAB to be truly SPD. So while the Higham algorithm will ensure positive semi-definite, if chol should always work, then it will indeed be positive definite.

Comments and Ratings on John D'Errico's Files View all
Updated File Comment by Comments Rating
21 Nov 2014 Estimatenoise Noise variance estimation from a signal vector or array Author: John D'Errico Ashkan

20 Nov 2014 allwords Parse a sentence or any string into distinct "words" Author: John D'Errico Lukas

12 Nov 2014 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Judith

This is a fantastic function and it runs perfectly with my 2D-data. Do you also provide a gridfit3d version? That whould save a lot of time in my post-processing work. Thanks in advance.

10 Nov 2014 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico John D'Errico


10 Nov 2014 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Chaipichit

How to cited your code in research paper?

Contact us