rickhg12hs wrote:
> On Jun 20, 10:18 pm, Robert Bradshaw <rober...@math.washington.edu>
> wrote:
>> sage: n = 10
>> sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n), 0])
>> sage: m.subdivide() # get rid of the block divisions
>> sage: m
>> [0 0 0 0 0 0 0 0 0 0 0]
>> [1 0 0 0 0 0 0 0 0 0 0]
>> [0 1 0 0 0 0 0 0 0 0 0]
>> [0 0 1 0 0 0 0 0 0 0 0]
>> [0 0 0 1 0 0 0 0 0 0 0]
>> [0 0 0 0 1 0 0 0 0 0 0]
>> [0 0 0 0 0 1 0 0 0 0 0]
>> [0 0 0 0 0 0 1 0 0 0 0]
>> [0 0 0 0 0 0 0 1 0 0 0]
>> [0 0 0 0 0 0 0 0 1 0 0]
>> [0 0 0 0 0 0 0 0 0 1 0]
>>
>> You can also use this to get anything you want on the sub-diagonal  
>> (or pretty much anywhere).
>>
>> sage: m = block_matrix([0, zero_matrix(1,1), diagonal_matrix([10, 20,  
>> 30, 40]), 0]); m.subdivide(); m
>> [ 0  0  0  0  0]
>> [10  0  0  0  0]
>> [ 0 20  0  0  0]
>> [ 0  0 30  0  0]
>> [ 0  0  0 40  0]
> 
> Very nice - I didn't know about block_matrix.  In addition, it seems
> block_matrix has an optional argument "subdivide".
> 
> sage: n = 10
> sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n),
> 0],subdivide=False)
> sage: m
> [0 0 0 0 0 0 0 0 0 0 0]
> [1 0 0 0 0 0 0 0 0 0 0]
> [0 1 0 0 0 0 0 0 0 0 0]
> [0 0 1 0 0 0 0 0 0 0 0]
> [0 0 0 1 0 0 0 0 0 0 0]
> [0 0 0 0 1 0 0 0 0 0 0]
> [0 0 0 0 0 1 0 0 0 0 0]
> [0 0 0 0 0 0 1 0 0 0 0]
> [0 0 0 0 0 0 0 1 0 0 0]
> [0 0 0 0 0 0 0 0 1 0 0]
> [0 0 0 0 0 0 0 0 0 1 0]
> 


I should mention that these methods are all nice for this problem, but 
they also end up copying an awful lot of zeros.  I think it would be way 
more efficient in general to make a zero matrix, then set the right 
diagonal by hand using a for loop.

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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to