On 3/14/11 11:02 PM, Justin C. Walker wrote:
Hi, and Welcome,
On Mar 14, 2011, at 20:14 , Ben123 wrote:
Hello. I'm a new user to Sage. I am trying to create a matrix without
knowing the values when it is initialized. All the examples I see have
static matrices like
A = matrix(QQ,2,2,[2,1,1,2])
My goal is to create a 2x2 matrix which I can then give values for
later
A[1][1]=5
That is correct, although I am at a loss to explain why that's how it is.
With your matrix,
sage: A[1]
(1, 2)
so clearly, the rows are "tuples", which are immutable.
Not all is lost, though:
sage: A[1,1]=5
sage: A
[2 1]
[1 5]
Perhaps someone with a closer understanding of the implementation can explain
the details.
A[i] gives back the ith row as a vector which you cannot change; think
of it as a copy of the ith row.
To change the entries in the matrix, you need to use both indices in a
single bracket, like Justin mentioned above. Sage also supports
assigning whole submatrices at once. See
http://www.sagemath.org/doc/reference/sage/matrix/docs.html#indexing
Jason
--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org