Ask Your Question
0

Can I get a exact solution for SVD?

asked 2012-04-07 10:53:22 +0100

QuantLabId gravatar image

updated 2012-04-07 10:54:08 +0100

Here's an example.

A=matrix(RDF,2,2,[1/2,-1/2,-1/2,1/2]) A.SVD()

<result> ( [-0.707106781187 0.707106781187] [ 0.707106781187 0.707106781187],

[ 1.0 0.0] [ 0.0 7.85046229342e-17],

[-0.707106781187 0.707106781187] [ 0.707106781187 0.707106781187] )

The exact solution is -1/sqrt(2),1/sqrt(2), 1/sqrt(2), 1/sqrt(2)

and D=(1, 0),(0, 0)

Something like this... http://www.wolframalpha.com/input/?i=SVD+%7B%7B1%2F2%2C+-1%2F2%7D%2C%7B-1%2F2%2C+1%2F2%7D%7D

Is there a way to get the exact solution?

One more question... Why doesn't the next code work?

A=matrix(RR,2,2,[1/2,-1/2,-1/2,1/2]) A.SVD()

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-04-08 12:18:59 +0100

Volker Braun gravatar image

Note that the type of output depends on the base ring of the matrix, for example a floating point (double) matrix

sage: matrix(RDF,[[1/2,-1/4],[-1/2,1/3]]).eigenvalues()
[0.779908245295, 0.0534250880383]

yields a floating-point result. A matrix over the rationals

sage: matrix(QQ,[[1/2,-1/4],[-1/2,1/3]]).eigenvalues()
[0.05342508803827721?, 0.779908245295057?]

returns eigenvalues in the splitting field which uses interval arithmetic. For arbitrary precision floating point numbers, there is no special implementation,

sage: matrix(RR,[[1/2,-1/4],[-1/2,1/3]]).eigenvalues()
/home/vbraun/opt/sage-5.0.beta11/local/bin/sage-ipython:1: UserWarning: Using generic algorithm for an inexact ring, which will probably give incorrect results due to numerical precision issues.
  #!/usr/bin/env python
[0.779908245295056, 0.0534250880382772]

so Sage falls back to the lapack implementation which doesn't track precision. Finally, over the symbolic ring

sage: matrix(SR,[[1/2,-1/4],[-1/2,1/3]]).eigenvalues()
[-1/12*sqrt(19) + 5/12, 1/12*sqrt(19) + 5/12]

Sage computes the symbolic answer.

Now to your question, nobody has implemented SVD for matrices with base field other than floating point numbers (the only implementation is via lapack). Probably because the real utility of the SVD is that there are efficient numerical ways to compute it, while the symbolic answer is almost always going to be a huge mess of roots.

A possible project would be to implement SVD for more base fields, for example starting with the explicit formula for 2x2 matrices.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-07 10:53:22 +0100

Seen: 1,628 times

Last updated: Apr 08 '12