On Sat, Jan 9, 2010 at 7:37 AM, <calcp...@aol.com> wrote: > >>> Then in Analysis class we hit matrices this week, and Sage was perfect > for this. I was able to show the kids how a matrix is just a list of lists, > and I showed how simple it is to create a 'dumb' matrix in Python and then > how to make it a 'smart' matrix in Sage. > << > > Could you give an example of this? >
Sure - here's a 'dumb' matrix in pure Python: M = [[2, 7, 6], [9, 5, 1], [4, 3, 8]] It is quite literally just a list of lists. Structurally it's a matrix, but it doesn't yet know how to act like a matrix. However, with just this much you can illustrate indexing: M[0] returns [2, 7, 6]. M[1][1] returns 5, etc. Now we can make it a 'smart' matrix: M = matrix(M) Magic! M can now do all kinds of useful matrixy things. Indexing works just as before. If we want to find out what else we can do, we type 'M.' followed by TAB. Wow! I don't even know what most of that stuff is! : ) One little detail - if we want our matrix to be able to handle rationals or reals we have to indicate that with a 'QQ' or an 'RR' in the parameter list, but one step at a time. In a truly integrated computational thinking math class, I think it would be a good exercise to think about how to write at least some of the typical matrix functions to handle dumb matrices from scratch. For example, dot product: def dot_product(row, col): return sum([r*c for (r, c) in zip(row, col)]) I love that! From there we could write columns(M), a function that would extract the columns from a dumb matrix, and from there we could create matrix_product(A, B) that would build another dumb matrix from the dot products of the rows in A and the columns of B. And if the kids were really good, we could even create our own simple little matrix class, just to get a sense for these things. But clearly this would be overwhelming in a typical Analysis course. - Michel--
You received this message because you are subscribed to the Google Groups "sage-edu" group.
To post to this group, send email to sage-...@googlegroups.com.
To unsubscribe from this group, send email to sage-edu+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sage-edu?hl=en.