Kim, In-Jae wrote:
> Sorry, I meant 20 by 20 matrix in the previous e-mail.
>
Remember that matrices in Sage start at column and row 0 (not 1). I've
adjusted your description below by subtracting one from each of your
numbers.
I think the best way to do this type of function is to define a function
that, given i,j, gives back the entry. Then just create a matrix from
the list generated by the function:
sage: def entries(i,j):
if i in [0..4] and j in [0..19]:
return 1
elif i in [5..18]:
return 3
else:
return -1
....:
sage: a=matrix(QQ, 20, [entries(i,j) for i in [0..19] for j in [0..19]])
sage: print a.str()
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
> ________________________________________
> From: [email protected] [[email protected]] On Behalf
> Of Kim, In-Jae [[email protected]]
> Sent: Thursday, June 04, 2009 3:19 PM
> To: [email protected]
> Subject: [sage-support] Re: matrix with many repeated entries
>
> Thank you for your help, Jason.
>
> Can I get some help on the following matrix too?
>
> a_{i,j} = 1 for 1 \leq i \leq 5 and j \in \{1,2,3, 7, ..., 20};
> a_{i,j} =3 for i \in \{6, 7, 13, ..., 19\};
> a_{ij}=-1 otherwise
>
>
>> P.S. If you have any suggestions for improving the linear algebra or
>> making it easier to use, we'd love to hear them!
>
> I would be happy to do so (I just started to use sage though).
>
> In-Jae
>
> ________________________________________
> From: [email protected] [[email protected]] On Behalf
> Of Jason Grout [[email protected]]
> Sent: Thursday, June 04, 2009 1:43 PM
> To: [email protected]
> Subject: [sage-support] Re: matrix with many repeated entries
>
> Kim, In-Jae wrote:
>> Hello,
>>
>> I would like to create a matrix with many repeated entries, for example, a
>> matrix with all entries equal to 1.
>> How can I do this efficiently when the size of the matrix is large?
>>
>
> Hi In-Jae,
>
> In Python (i.e., Sage), you can duplicate a list by multiplying it by a
> number:
>
> sage: [1]*20
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>
> So you would just use that to create a list long enough for your matrix:
>
> sage: matrix(4,5,[1]*20)
>
> [1 1 1 1 1]
> [1 1 1 1 1]
> [1 1 1 1 1]
> [1 1 1 1 1]
>
> Thanks,
>
> Jason
>
> P.S. If you have any suggestions for improving the linear algebra or
> making it easier to use, we'd love to hear them!
>
>
> --
> Jason Grout
>
>
>
>
> >
>
--
Jason Grout
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---