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.

-Marshall

On Dec 13, 3:31 am, David Joyner <wdjoy...@gmail.com> wrote:
> On Sat, Dec 12, 2009 at 11:09 PM, Minh Nguyen <nguyenmi...@gmail.com> wrote:
> > Hi David,
>
> > On Sun, Dec 13, 2009 at 11:20 AM, David Joyner <wdjoy...@gmail.com> wrote:
>
> > <SNIP>
>
> >> I think this would fit nicely in the constructions document.
> >> Adding an example of how to use map for Sage matrices might
> >> be worth thinking about.
>
> > I have provided some examples on using lambda and map() to construct 
> > matrices.
>
> Nice examples, thanks.
>
>
>
> >> I think one person asked me about that
> >> recently and it would have been nice to point them to something.
>
> > Do you still remember the question? I don't know what's required so
> > the matrix examples are rather simple.
>
> Here is a related non-example, which tries to create ain integer
> (-1,1) matrix from a GF(2) matrix in the (wrong but) obvious way:
>
> sage: A = random_matrix(GF(2), 2, 3)
> sage: A
>
> [0 1 1]
> [0 1 0]
> sage: f = lambda x: 2*ZZ(x)-1
> sage: map(f,A)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> One right way is to use the list of elements:
>
> sage: A = random_matrix(GF(2), 2, 3); A
>
> [0 1 0]
> [0 0 1]
> sage: f = lambda x: 2*ZZ(x)-1
> sage: B = matrix(ZZ, 2, 3, map(f, A.list())); B
>
> [-1  1 -1]
> [-1 -1  1]
>
> The actual question I don't remember exactly.
> But we were arguing about matlab vs Sage.
>
> Going form a vague memory:
> My colleague was arguing that one should not teach
> a course in scientific programming using Sage
> because it was so slow in doing some very simple
> things. Apparently if A is a vector or matrix in matlab
> (ie, an array or real numbers) and f is a function
> (eg, a sin or a polynomial), then f(A) is both
> easy for the student to write and also super
> optimized. He doubted Sage could do that.
> So for large sized arrays with thousands of entries,
> matlab would leave Sage in the dust.
>
> My only argument, if I remember, was that his
> argument did not make intuitive sense. I said that
> though I didn't know off the top of my head
> how to write down the evaluation of a function
> on a matrix in an optimized way, there must exist one.
> With scipy used in industry for serious number-crunching,
> it must be possible.
>
> Of course an example would be more convincing that
> an existence argument:-) An example which would be
> both easy for the student to perform (and also fast) would be
> nice,
>
>
>
> > --
> > Regards
> > Minh Van Nguyen
>
> > --
> > 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 
> > athttp://groups.google.com/group/sage-devel
> > URL:http://www.sagemath.org

-- 
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