Ask Your Question

# singular value decomposition

I want to use SVD directly in Sage, is it possible?

from http://wiki.sagemath.org/interact/lin..., I know that, we can...

sage: from scipy import linalg

sage: U,s,Vh = linalg.svd(A) # A is a fixed matrix, e.g., A = [1, 2; 3, 4]

Thanks in advance!

edit retag close merge delete

## Comments

Can you explain what you mean by use SVD directly? The commands you mentioned is the way to use SVD. Is there any other way you wish to do it?

( 2013-11-07 12:55:13 +0200 )edit

## 1 Answer

Sort by ยป oldest newest most voted

It depends on the ring of the matrix. For example, it works for matrices over CDF:

sage: M = matrix(CDF, [[1,2,3],[1,4,6]])
sage: M.SVD()
(
[-0.455252372951 -0.890362441325]
[-0.890362441325  0.455252372951],

[ 8.17345734477            0.0            0.0]
[           0.0 0.441129270439            0.0],

[   -0.164632267291    -0.986355015482 -2.81388521797e-16]
[   -0.547131320636    0.0913215509714    -0.832050294338]
[   -0.820696980953     0.136982326457     0.554700196225]
)


but not for matrices over QQ:

sage: M = matrix(QQ, [[1,2,3],[1,4,6]])
sage: M.SVD()
AttributeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object has no attribute 'SVD'


So, the method .SVD() is not implemented for every kind of matrices.

more

## Comments

.SVD() works for CDF and RDF. Thanks!

( 2013-11-08 08:19:42 +0200 )edit

## Your Answer

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

Add Answer

## Stats

Asked: 2013-11-07 11:13:41 +0200

Seen: 2,656 times

Last updated: Nov 07 '13