I just figured out what were wrong in the last command.
For those who might have a similar question, I put a correct one (that I
obtained by mimicking what Javier showed to me) in the following:
p=20; q=20; r=1; s=2; t=2;
def a(i,j):
for k in [1..t]:
if (r*(k-1)+1 <= i <= r*k) and (s*(k-1)+1 <= j <= s*k):
return 2
else:
return 3
Thank you.
In-Jae
________________________________________
From: [email protected] [[email protected]] On Behalf
Of Kim, In-Jae [[email protected]]
Sent: Saturday, June 06, 2009 10:24 AM
To: [email protected]
Subject: [sage-support] Re: matrix with many repeated entries
Thank you all for excellent help on the question.
I have another question along this line:
For p=20, q=20, r=1, s=2, t=2, I would like to define matrix
A=[a(i,j)] such that
for k in range(1,t+1), a(i,j)=2 if ((r*(k-1)+1 <= i <= r*k) and (s*(k-1)+1 <= j
<= s*k)), and
all other entries are 3.
I have tried the following which has a syntax error:
p=20; q=20; r=1; s=2; t=2;
def a(i,j):
For k in range(1,t+1):
if ((r*(k-1)+1 <= i <= r*k) and (s*(k-1)+1 <= j <= s*k)):
return 2
return 3
Syntax Error:
if ((r*(k-1)+1 <= i <= r*k) and (s*(k-1)+1 <= j
<= s*k)):
Can I get some help on this?
Thank you.
In-Jae
________________________________________
From: [email protected] [[email protected]] On Behalf
Of javier [[email protected]]
Sent: Thursday, June 04, 2009 5:13 PM
To: sage-support
Subject: [sage-support] Re: matrix with many repeated entries
I dont quite understand the defining rule for your matrix, but in
general you can just put whichever rule you have as a function
def f(i,j):
if ((i<=5) and (j in [1,2,3, 7, ..., 20]))
return 1
if i in [6,7,13,..., 20]:
return 3
return -1
and then create your matrix using this function:
m = Matrix([[ f(i,j) for j in [1..20]] for i in [1..20]])
For this to work, the sets in the definition of f have to be well
defined.
Hope this helps
Cheers
Javier
On Jun 4, 9:19 pm, "Kim, In-Jae" <[email protected]> wrote:
> 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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---