<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Matrix multiplication in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266406#M2691</link>
    <description>&lt;P&gt;Thank you Rick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I am trying to accomplish&lt;/P&gt;&lt;P&gt;I have two matrices&lt;BR /&gt;P=mXm&lt;BR /&gt;V=mX1&lt;BR /&gt;and a saclar value m&lt;/P&gt;&lt;P&gt;I am looking for a sas iml code to do the following&lt;/P&gt;&lt;P&gt;Run a loop for 10 times say, to get the final result of F.&lt;BR /&gt;where P=P at the befining for second run it should be p=P*P, and at the end (for 10) is should be&lt;BR /&gt;p=p*p*p*p*p*p*p*p*p*p&lt;/P&gt;&lt;P&gt;C=P*v;&lt;BR /&gt;D=V+C;&lt;BR /&gt;F=D*m;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2016 14:55:32 GMT</pubDate>
    <dc:creator>ambalath1</dc:creator>
    <dc:date>2016-04-26T14:55:32Z</dc:date>
    <item>
      <title>Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265635#M2673</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a n*n matrix A and I would like to calculate A2=A*A , A3=A2*A, A4=A3*A ... A60=A59*A. Can any one help me writing a do loop to perform this task ? I have never used IML before. I do have a piece of code to complete the same task in R.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 12:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265635#M2673</guid>
      <dc:creator>ambalath1</dc:creator>
      <dc:date>2016-04-22T12:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265649#M2674</link>
      <description>&lt;P&gt;You could use the matrix power operator ** to achieve this.&amp;nbsp;&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  a = 1.01 # i(3);
  b = a**60;
  print a, b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or is it important to retain all the lower powers of a?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 14:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265649#M2674</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2016-04-22T14:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265650#M2675</link>
      <description>&lt;P&gt;Hi IanWakeling,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would have to use all the 60 matrices for some other calculations. Having said, I need A2, A3.. A60 to perform one more computation.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 14:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265650#M2675</guid>
      <dc:creator>ambalath1</dc:creator>
      <dc:date>2016-04-22T14:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265653#M2676</link>
      <description>&lt;P&gt;Unless n is very large, and efficiency is important,&amp;nbsp;&amp;nbsp;then I would be tempted to calculate the powers as and when you need them.&amp;nbsp; i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; a**10&amp;nbsp;&amp;nbsp; +&amp;nbsp;&amp;nbsp; a**20;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is&amp;nbsp;is much more difficult if&amp;nbsp;&amp;nbsp;you want to&amp;nbsp;save the whole sequence of matrices A1, A2,A3, etc...&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 14:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265653#M2676</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2016-04-22T14:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265686#M2677</link>
      <description>&lt;P&gt;If you want to store all the matrices, then I think you will have to stack&amp;nbsp;them together&amp;nbsp;inside one large matrix.&amp;nbsp;This complicates things as you need to keep track of where in the larger matrix, the individual matrices are stored.&amp;nbsp;&amp;nbsp;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   n = 3;
   maxp = 60;
   ap = j(maxp#n, n); /* large matrix in which to keep all the powers of a */
   ri = shape(1:(maxp#n), maxp); /* row index matrix for sub-matrices in ap */

   a = 1.01 # i(n); /* define the matrix a */

   ap[ ri[ 1, ], ] = a;  /* write matrix a to ap */
   do i = 2 to maxp;     /* write powers to ap */
     ap[ ri[ i, ], ] = ap [ ri[ i-1, ], ] * a; 
   end;

   c = ap[ ri[ 3, ], ];  /* set c to to a**3 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 16:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265686#M2677</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2016-04-22T16:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265737#M2678</link>
      <description>Thank you</description>
      <pubDate>Fri, 22 Apr 2016 18:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265737#M2678</guid>
      <dc:creator>ambalath1</dc:creator>
      <dc:date>2016-04-22T18:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265811#M2681</link>
      <description>Do You want create many Matrix A2-A60 to represent that calculation?

&lt;PRE&gt;
proc iml;
call randseed(1234);
A=j(4,4);
call randgen(A,'uniform');
x={'A'}+left(char(2:60));
B=A;
do i=1 to 59;
 B=B*A;
 call valset(x[i],B);
end;




print A;
do i=1 to 59;
 temp=value(x[i]);
 label=x[i];
 print temp[l=label];
end;
quit;



&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Apr 2016 11:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265811#M2681</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-23T11:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265812#M2682</link>
      <description>&lt;P&gt;The use of the VALSET and VALUE functions are described in the article "&lt;A href="http://blogs.sas.com/content/iml/2011/03/23/indirect-assignment-how-to-create-and-use-matrices-named-x1-x2-xn.html" target="_self"&gt;Indirect assignment.&lt;/A&gt;"&amp;nbsp; However, it is rare to need to use this technique. Almost always, you can avoid indirect assignment and use the matrices inside the DO loop without saving them into 60 different named matrices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to acheive? That would help us know what programming technique to suggest.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2016 11:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/265812#M2682</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-04-23T11:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266406#M2691</link>
      <description>&lt;P&gt;Thank you Rick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I am trying to accomplish&lt;/P&gt;&lt;P&gt;I have two matrices&lt;BR /&gt;P=mXm&lt;BR /&gt;V=mX1&lt;BR /&gt;and a saclar value m&lt;/P&gt;&lt;P&gt;I am looking for a sas iml code to do the following&lt;/P&gt;&lt;P&gt;Run a loop for 10 times say, to get the final result of F.&lt;BR /&gt;where P=P at the befining for second run it should be p=P*P, and at the end (for 10) is should be&lt;BR /&gt;p=p*p*p*p*p*p*p*p*p*p&lt;/P&gt;&lt;P&gt;C=P*v;&lt;BR /&gt;D=V+C;&lt;BR /&gt;F=D*m;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 14:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266406#M2691</guid>
      <dc:creator>ambalath1</dc:creator>
      <dc:date>2016-04-26T14:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266483#M2692</link>
      <description>&lt;P&gt;As I said when you asked this question on my blog, initialize the result matrix&amp;nbsp;(P) to the identity matrix. Then loop, each time multiplying the current value of&amp;nbsp;P times the original matrix.&amp;nbsp; The other computations just "go along for the ride."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
X = {1 2 3,
    -1 0 1,
     2 1 0};
V = {-1, 0, 1};

m = nrow(V);
P = I(m);
do i = 1 to 10;
   P = P*X;
   C = P*V;
   D = V+C;
   F = D*m;
end;
/* at end of loop, P = X**10 */
print P C D F;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2016 18:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266483#M2692</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-04-26T18:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266519#M2693</link>
      <description>Thank you Rick!</description>
      <pubDate>Tue, 26 Apr 2016 20:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-multiplication/m-p/266519#M2693</guid>
      <dc:creator>ambalath1</dc:creator>
      <dc:date>2016-04-26T20:03:14Z</dc:date>
    </item>
  </channel>
</rss>

