9

I am finding it difficult to compute the condition number of a matrix using Mathematica. There is no built-in function, it seems, for this task. MatLab and Numpy have it. All stack searches point to some old linear algebra package.

m={{-639445.,-336053.,0.,0.,0.,0.,0.,0.683542,0.,0.151787},{-336053.,-7.4485*10^6,0.,0.,0.,0.,0.,-0.0000174204,0.,0.808413},{0.,0.,-6.19065*10^15,2.20989*10^10,0.,0.,0.,0.,0.,-1427.52},{0.,0.,2.20989*10^10,-6.50127*10^16,0.,0.,0.,0.,0.,2496.12},{0.,0.,0.,0.,-4.19983*10^9,0.,0.,0.,1.33685*10^-12,0.},{0.,0.,0.,0.,0.,-6.1685*10^11,0.,-1.,0.,0.},{0.,0.,0.,0.,0.,0.,-5.55165*10^12,1.,0.,0.},{0.683542,-0.0000174204,0.,0.,0.,-1.,1.,0.,0.,0.},{0.,0.,0.,0.,1.33685*10^-12,0.,0.,0.,0.,0.},{0.151787,0.808413,-1427.52,2496.12,0.,0.,0.,0.,0.,0.}}

How can I compute the condition number for matrix m?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Nanavanalla
  • 427
  • 2
  • 8

3 Answers3

8

MatLab and Numpy has it

Mathematica has it also, but hiding in the following function

 LUDecomposition[m][[3]]

Mathematica graphics

enter image description here

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • But how to compute p-2 norm – Nanavanalla May 07 '22 at 12:35
  • @VijayKumarS for p-2, you can check the other quesition in the link given in the comments to your question. I agree that Mathematica should really have a dedicated function condition number using different norms and not just infinity. – Nasser May 07 '22 at 12:49
  • I tried with LinearAlgebraMatrixConditionNumber[m, Norm -> 2]`, its not working. I think its time for mathematica to introduce a function to calculate the condition number insted on relaying on by products of other functions. – Nanavanalla May 07 '22 at 14:37
  • 2
    @VijayKumarS The internals of the LinearAlgebra context have changed a few times. It is not an official (documented) part of Mathematica. The function is now found as LinearAlgebra`Private`MatrixConditionNumber[m, Norm -> p] (see yode's and my answers); but only p = 1 and p = Infinity are currently supported. For the 2-norm, use SingularValueList. – Michael E2 May 07 '22 at 17:17
8
LinearAlgebra`Private`MatrixConditionNumber[m]

1.52779*10^50

yode
  • 26,686
  • 4
  • 62
  • 167
8

It's also hidden in

LinearSolve[m]@"ConditionNumber"
(*  1.52779*10^50  *)

This gives the infinity norm (from the LU decomposition).

The 1-norm may be obtained with

LinearAlgebra`Private`MatrixConditionNumber[m, Norm -> 1]

It's the same in this case because m is symmetric.

And the 2-norm may be obtained from SingularValueList, as may be found in the Q&A, How to estimate the matrix condition number in the 2-Norm? (For a large matrix, one can compute the largest and smallest singular values separately.)

Michael E2
  • 235,386
  • 17
  • 334
  • 747