| Date: | Wed, 13 Jun 2007 14:13:31 -0000 |
| Reply-To: | "J. Manuel Picaza" <JMPicaza@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "J. Manuel Picaza" <JMPicaza@GMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: problem with calculation of a matrix |
|
| In-Reply-To: | <1181729857.317353.25920@a26g2000pre.googlegroups.com> |
| Content-Type: | text/plain; charset="us-ascii" |
|---|
On Jun 13, 12:17 pm, PBilin <pbi...@gmail.com> wrote:
> Dear SAS users,
>
> I would appreciate any help with the following problem. I have a
> vector of numbers as follows:
> 1
> 2
> 3
> 4
> 5
> ;
>
> and would like to obtain a matrix where:
>
> -on diagonal I have: ai^2 if i=j
> -off-diagonal I have either: ai*aj if 1<=abs(i-j)<=10 or: 0
>
> So the matrix looks more or less like that:
>
> 1*1 1*2 1*3........0 0 0
> 2*1 2*2 2*3.. ......0 0 0
> 3*1 3*2 3*3..................
> ................ .11*11 11*12
> 0 0 0 .... .... 12*11 12*12
>
> Can anyone help me with some code? I am new to IML and would
> appreciate some guidance. Thank you!
>
> Paul
Hi Paul,
In IML you have to 'Think' in matrices. If you have not done it before
(matlab knowledge) is going to be hard at the begining. Be patient and
review all matrix algebra you can get (on wikipedia, for example). It
really is going to help you a lot.
About your problem:
you have the vector:
1
2
3
4
5
but whet you are trying to do is:
|1 1 1 1 1| |1 1 1 1 1|
|2 2 2 2 2| |2 2 2 2 2|
|3 3 3 3 3| * |3 3 3 3 3|
|4 4 4 4 4| |4 4 4 4 4|
|5 5 5 5 5| |5 5 5 5 5|
in a first step and then change to 0 depending on abs(i-j)
CODE IN IML:
proc iml;
a={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
b=repeat(a,1,nrow(a));
c=b*b;
do i=1 to nrow(c);
do j=1 to ncol(c);
if abs(i-j)>10 then c[i,j]=0;
end;
end;
print c;
quit;
Let mi know if you need further explanations.
Regards,
J.
|