Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The Mathematica documentation say it is possible to estimate the Matrix condition number in norm 1, 2, Infinity. But the 2-Norm raise a message.

This is an extract from reference documentation "tutorial/LinearAlgebraMatrixComputations" where I changed the expression to compute the 2-Norm.

error

UPDATE

As requested, if you want to try by yourself and check the error on your system, simply type:

mat = {{1., 2.}, {3., 4.}};
LinearAlgebra`MatrixConditionNumber[mat, Norm -> 2]
share|improve this question
    
You can compute it yourself with Norm[mat,2]Norm[Inverse@mat,2], but this is unsatisfying... –  jtbandes Jul 17 at 6:27
    
@jtbandes yes, possible, but unsatisfying... –  unlikely Jul 17 at 6:36
    
You can estimate the L_infinity condition number of a square matrix via LUDecomposition (the third part of the result is that estimate). For the 1-norm take the LUDecomposition of the transpose. –  Daniel Lichtblau Jul 17 at 21:47

2 Answers 2

up vote 6 down vote accepted

The compatibility information at Compatibility/tutorial/LinearAlgebra/MatrixManipulation says

These functions were available in previous versions of Mathematica and are now available on the web at library.wolfram.com/infocenter/MathSource/6770:

LinearEquationsToMatrices
InverseMatrixNorm
ConditionNumber

You can download the original package there. It's too long to provide an excerpt here, but you can load it and use it in your code as-is.

(There seems to be a vestigial version of LinearAlgebra`MatrixConditionNumber which, as you noticed, only supports norms 1 and ∞.)

On the other hand, if you are okay with the computation involved in producing an exact answer, the documentation for SingularValueList says

The 2-norm of a matrix is equal to the largest singular value … The 2-norm of the inverse is equal to the reciprocal of the smallest singular value … [Thus,] The condition number of the matrix is equal to the ratio of largest to smallest singular values.

So you can use:

First@#/Last@#& @ SingularValueList[mat]


Performance

The old implementation for 2-norms is considerably faster for large random matrices (it is worth noting that both implementations seem to take advantage of multiple cores):

performance

While the relative error stays low (this may depend on the precision of your input):

error

share|improve this answer
    
I'm not against an exact answer, but I'm against the time required for an exact answer if the matrix is very large. The documentation suggest the MatrixConditionNumber function returns a fast, approximate, answer, for large, poterntially banded or sparse, matrices, and this is what I'm searching for. I'll give a try to the old package... –  unlikely Jul 17 at 6:53
    
The last edit is detailed and interesting. A question that arise is why this old function is now deprecated (and also why the documentation is out of sync): maybe there are some issue using this estimate? For example I noticed I often get large errors in the estimate with small matrices. And for small matrices the exact computation is often faster. –  unlikely Jul 17 at 12:32
    
The best idea is probably to extract from the old package the relevant definitions for the estimate of the spectral condition number, and write a helper function that dispatch the request to the built-in Norm (for 1 and Infinity norm), to the old package function for the 2-Norm and large matrices, to the exact computation function for the 2-Norm and small matrices... Strange that Wolfram forgot to do this... –  unlikely Jul 17 at 12:33
    
That sounds reasonable; the threshold would of course be up to you, based on the computational speed you need. –  jtbandes Jul 17 at 16:41

The LinearAlgebra package has been deprecated since Mathematica 5, and is no longer bundled with Mathematica 9 or newer. You can still download a part of it (which contains the MatrixConditionNumber function) at the URL that jtbandes gave in his answer.

First, we need to load the package:

(* Be sure to install the above linked package in a "LinearAlgebra" subfolder for M9. *)
<< LinearAlgebra`MatrixManipulation`

Now if you call MatrixConditionNumber without a context in front it works and with the second argument as a single number instead of an option, it works:

MatrixConditionNumber[{{1., 2.}, {3., 4.}}, 2]

14.933

Note that you can do this without the LinearAlgebra package as follows:

Max[#]/Min[#]& @ SingularValueList[ Inverse[{{1., 2.}, {3., 4.}}] ]

14.933

share|improve this answer
    
The former doesn't work for me in Mathematica 10. Did you need to import anything for it to work? –  jtbandes Jul 17 at 6:31
1  
@jtbandes You'll need to load the LinearAlgebra package first, but they stopped shipping it with Mathematica 9 onwards. –  Teake Nutma Jul 17 at 6:34
1  
Interestingly, though it appears in blue, LinearAlgebra`MatrixConditionNumber works (with the same problem as OP) –  jtbandes Jul 17 at 6:35
    
By the way, SingularValueList returns a sorted list, so you can use First@#/Last@#&. –  jtbandes Jul 17 at 6:37
    
Teh former doesen't work for me in Mathematica 9... –  unlikely Jul 17 at 6:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.