mhampton wrote:
> If you convert to numpy matrices, then Sage is pretty competitive with
> matlab.  We still have some room for improvement in making it easy
> though - despite Jason Grout's improvements, a matrix over RDF is
> missing some methods I'd like, such as the singular value
> decomposition.  As an example, to extend one of Minh's examples to get
> the smallest singular value of a bunch of matrices you'd have to do
> something like:
> 
> sage: rand_row = lambda n: [randint(1, 10) for i in xrange(n)]
> sage: rand_mat = lambda nrows, ncols: [rand_row(ncols) for i in xrange
> (nrows)]
> sage: rows = [randint(1, 10) for i in xrange(10)]
> sage: cols = [randint(1, 10) for i in xrange(10)]
> sage: M = map(rand_mat, rows, cols)
> sage: M = map(matrix, M)
> 
> sage: from numpy.linalg import svd
> sage: smallest_singular_values = lambda x: min(svd(x.numpy())[1])
> sage: ssvM = map(smallest_singular_values,M)
> 
> Or perhaps I'm missing something and that import isn't necessary.



Use .SVD():


sage: a=random_matrix(RDF,4)
sage: a
[-0.0589149680447  -0.171553538689  0.0504191493106  -0.728358759815]
[  0.939727693257  -0.367536042534  -0.721360348176  0.0692413755066]
[ -0.265450259774 -0.0414843551839   0.329102195484  -0.152151468706]
[  0.166692127509  -0.107846656469  -0.964097402323  -0.752787313591]
sage: a.SVD()
(
[ 0.136357448911  0.618194289876   0.67734122822 -0.374768363984]
[ 0.678366688256 -0.550596271759  0.457486597867  0.165433958308]
[-0.204023508917  0.263478231509  0.295912033247  0.895203718664]
[ 0.692531364055  0.495236092193 -0.494318664329  0.175472450502],

[ 1.59046610372            0.0            0.0            0.0]
[           0.0  1.05246085825            0.0            0.0]
[           0.0            0.0 0.455098193519            0.0]
[           0.0            0.0            0.0 0.064329905844],

[ 0.502396175818 -0.514242277172  0.503316286102 -0.479401375714]
[-0.213107477417 0.0303771634211 -0.534627925294  -0.81721197526]
[-0.765363106349 0.0357282483633  0.611065745739    -0.198850351]
[-0.341178254043  -0.85636183975 -0.295709911949  0.250594186611]
)
sage:


What apparently is missing is that matrix/matrix_double_dense.pyx has 
not been converted to rest yet, so the SVD function does not show up in 
the reference manual.

Thanks,

Jason

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to