On Monday, March 14, 2011 9:02:48 PM UTC-7, 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.
>

sage: A[1]
(1, 2)
sage: type(A[1])
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: A[1].is_immutable()
True

So A[1] is a row vector, and those are immutable.  Trying to set A[1][1] is 
trying to modify an entry of this vector.
 

> Not all is lost, though:
>
> sage: A[1,1]=5
> sage: A 
> [2 1]
> [1 5]
>

According to <http://sagemath.org/doc/reference/sage/matrix/docs.html>, this 
seems to be the right way to change an entry of a matrix.  There seems to be 
generally helpful information in that documentation.

> Perhaps someone with a closer understanding of the implementation can 
> explain the details.
>
> HTH.
>
> Justin
>
> --
> Justin C. Walker, Curmudgeon-At-Large
> Institute for the Enhancement of the Director's Income
> --------
> When LuteFisk is outlawed,
> Only outlaws will have LuteFisk
>
Would this be bad?

-- 
John

 

 

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

Reply via email to