<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, Adding matrix diagonally</title>
    <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Thu, 11 Jun 2026 15:16:19 GMT</lastBuildDate>
    <pubDate>Thu, 11 Jun 2026 15:16:19 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, Adding matrix diagonally</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, Adding matrix diagonally</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally</link>
    </image>
    <item>
      <title>Own procedure.</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#answer130411</link>
      <itunes:summary>&lt;p&gt;I would create my own procedure for this. I don't know if there is anything "easier".&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit: The procedure could look like this (I suppose that L is a list of 3x3 matrices):&lt;/p&gt;
&lt;p&gt;diag_matrix := proc (L) &lt;br&gt;local M, i; &lt;br&gt;M := Vector(nops(L)): &lt;br&gt;M[1] := Matrix(2*nops(L)+1, L[1]); &lt;br&gt;&lt;br&gt;for i from 2 to nops(L) do &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; M[i] := LinearAlgebra[DiagonalMatrix]([Matrix(2*i-2), L[i], Matrix(2*(nops(L)-i))]) &lt;br&gt;end do; &lt;br&gt;&lt;br&gt;return add(M[i], i = 1 .. nops(L)); &lt;br&gt;end proc:&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I would create my own procedure for this. I don't know if there is anything "easier".&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit: The procedure could look like this (I suppose that L is a list of 3x3 matrices):&lt;/p&gt;
&lt;p&gt;diag_matrix := proc (L) &lt;br&gt;local M, i; &lt;br&gt;M := Vector(nops(L)): &lt;br&gt;M[1] := Matrix(2*nops(L)+1, L[1]); &lt;br&gt;&lt;br&gt;for i from 2 to nops(L) do &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; M[i] := LinearAlgebra[DiagonalMatrix]([Matrix(2*i-2), L[i], Matrix(2*(nops(L)-i))]) &lt;br&gt;end do; &lt;br&gt;&lt;br&gt;return add(M[i], i = 1 .. nops(L)); &lt;br&gt;end proc:&lt;/p&gt;</description>
      <guid>130411</guid>
      <pubDate>Tue, 07 Feb 2012 02:44:27 Z</pubDate>
      <itunes:author>Jarekkk</itunes:author>
      <author>Jarekkk</author>
    </item>
    <item>
      <title>overlap</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#answer130417</link>
      <itunes:summary>&lt;pre&gt;restart:
randomize():
interface(rtablesize=100):

N:=3:
number:=4:

L:=[seq(LinearAlgebra:-RandomMatrix(N),i=1..number)];

       [[ 58  -42  -62]  [ 62  -47  -79]  [-78  -85  39]  [ -2  -97   92]]
       [[             ]  [             ]  [            ]  [             ]]
  L := [[ 25   23  -88], [ -8  -71   -6], [-38   -3  56], [-13  -31  -34]]
       [[             ]  [             ]  [            ]  [             ]]
       [[-49  -53  -30]  [-15   57   79]  [-73   58  52]  [-86  -37  -92]]

M:=Matrix((N-1)*number+1):

for i from 1 to number do
   sz := (N-1)*(i-1)+1;
   M[sz..sz+N-1,sz..sz+N-1]:=
   M[sz..sz+N-1,sz..sz+N-1]+L[i];
end do:

M;

                [ 58  -42  -62    0    0    0    0    0    0]
                [                                           ]
                [ 25   23  -88    0    0    0    0    0    0]
                [                                           ]
                [-49  -53   32  -47  -79    0    0    0    0]
                [                                           ]
                [  0    0   -8  -71   -6    0    0    0    0]
                [                                           ]
                [  0    0  -15   57    1  -85   39    0    0]
                [                                           ]
                [  0    0    0    0  -38   -3   56    0    0]
                [                                           ]
                [  0    0    0    0  -73   58   50  -97   92]
                [                                           ]
                [  0    0    0    0    0    0  -13  -31  -34]
                [                                           ]
                [  0    0    0    0    0    0  -86  -37  -92]
&lt;/pre&gt;
&lt;p&gt;And as a procedure,&lt;/p&gt;
&lt;pre&gt;overlap:=proc(LL::list(Matrix(square)))
  local i, n, numb, m, rng, sz;
  n := op([1,1],LL[1]);
  numb := nops(LL);
  m:=Matrix((n-1)*numb+1):
  for i from 1 to numb do
    sz := (n-1)*(i-1)+1;
    rng := sz..sz+n-1;
    m[rng,rng] := m[rng,rng]+LL[i];
  end do:
  m;
end proc:

overlap(L);

                [ 58  -42  -62    0    0    0    0    0    0]
                [                                           ]
                [ 25   23  -88    0    0    0    0    0    0]
                [                                           ]
                [-49  -53   32  -47  -79    0    0    0    0]
                [                                           ]
                [  0    0   -8  -71   -6    0    0    0    0]
                [                                           ]
                [  0    0  -15   57    1  -85   39    0    0]
                [                                           ]
                [  0    0    0    0  -38   -3   56    0    0]
                [                                           ]
                [  0    0    0    0  -73   58   50  -97   92]
                [                                           ]
                [  0    0    0    0    0    0  -13  -31  -34]
                [                                           ]
                [  0    0    0    0    0    0  -86  -37  -92]
&lt;/pre&gt;</itunes:summary>
      <description>&lt;pre&gt;restart:
randomize():
interface(rtablesize=100):

N:=3:
number:=4:

L:=[seq(LinearAlgebra:-RandomMatrix(N),i=1..number)];

       [[ 58  -42  -62]  [ 62  -47  -79]  [-78  -85  39]  [ -2  -97   92]]
       [[             ]  [             ]  [            ]  [             ]]
  L := [[ 25   23  -88], [ -8  -71   -6], [-38   -3  56], [-13  -31  -34]]
       [[             ]  [             ]  [            ]  [             ]]
       [[-49  -53  -30]  [-15   57   79]  [-73   58  52]  [-86  -37  -92]]

M:=Matrix((N-1)*number+1):

for i from 1 to number do
   sz := (N-1)*(i-1)+1;
   M[sz..sz+N-1,sz..sz+N-1]:=
   M[sz..sz+N-1,sz..sz+N-1]+L[i];
end do:

M;

                [ 58  -42  -62    0    0    0    0    0    0]
                [                                           ]
                [ 25   23  -88    0    0    0    0    0    0]
                [                                           ]
                [-49  -53   32  -47  -79    0    0    0    0]
                [                                           ]
                [  0    0   -8  -71   -6    0    0    0    0]
                [                                           ]
                [  0    0  -15   57    1  -85   39    0    0]
                [                                           ]
                [  0    0    0    0  -38   -3   56    0    0]
                [                                           ]
                [  0    0    0    0  -73   58   50  -97   92]
                [                                           ]
                [  0    0    0    0    0    0  -13  -31  -34]
                [                                           ]
                [  0    0    0    0    0    0  -86  -37  -92]
&lt;/pre&gt;
&lt;p&gt;And as a procedure,&lt;/p&gt;
&lt;pre&gt;overlap:=proc(LL::list(Matrix(square)))
  local i, n, numb, m, rng, sz;
  n := op([1,1],LL[1]);
  numb := nops(LL);
  m:=Matrix((n-1)*numb+1):
  for i from 1 to numb do
    sz := (n-1)*(i-1)+1;
    rng := sz..sz+n-1;
    m[rng,rng] := m[rng,rng]+LL[i];
  end do:
  m;
end proc:

overlap(L);

                [ 58  -42  -62    0    0    0    0    0    0]
                [                                           ]
                [ 25   23  -88    0    0    0    0    0    0]
                [                                           ]
                [-49  -53   32  -47  -79    0    0    0    0]
                [                                           ]
                [  0    0   -8  -71   -6    0    0    0    0]
                [                                           ]
                [  0    0  -15   57    1  -85   39    0    0]
                [                                           ]
                [  0    0    0    0  -38   -3   56    0    0]
                [                                           ]
                [  0    0    0    0  -73   58   50  -97   92]
                [                                           ]
                [  0    0    0    0    0    0  -13  -31  -34]
                [                                           ]
                [  0    0    0    0    0    0  -86  -37  -92]
&lt;/pre&gt;</description>
      <guid>130417</guid>
      <pubDate>Tue, 07 Feb 2012 06:59:09 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>Hi, may I know why everytime I press enter,</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#comment130594</link>
      <itunes:summary>&lt;p&gt;Hi, may I know why everytime I press enter, the for loop gives me an increase in multiple of two? for example, first it gives me 58, then if i press enter gain, it gives me 116, and if i press enter again, it gives me 174 and so on...&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Hi, may I know why everytime I press enter, the for loop gives me an increase in multiple of two? for example, first it gives me 58, then if i press enter gain, it gives me 116, and if i press enter again, it gives me 174 and so on...&lt;/p&gt;</description>
      <guid>130594</guid>
      <pubDate>Sun, 12 Feb 2012 03:28:03 Z</pubDate>
      <itunes:author>serena88</itunes:author>
      <author>serena88</author>
    </item>
    <item>
      <title>Further on question</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#comment130634</link>
      <itunes:summary>&lt;p&gt;Hi, Thank you for your help.&lt;/p&gt;
&lt;p&gt;I have now a further question. I only have one matrix : se00:=Matrix([[4,2,-1],[2,16,2],[-1,2,4]])&lt;/p&gt;
&lt;p&gt;I want to add them up as above. Here is what I did :&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;num:=16&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;ie0:=Matrix(33)&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&lt;strong&gt;for&lt;/strong&gt; m&lt;strong&gt; from&lt;/strong&gt; 1 &lt;strong&gt;to&lt;/strong&gt; num-1 &lt;strong&gt;do&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n1:=m*2+1:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ie0[n1..n1+2,n1..n1+2]:=se00&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt; end do&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Problem&amp;nbsp;: it does not give me a 33x33 matrix&lt;/p&gt;
&lt;p&gt;Please advice.&lt;/p&gt;
&lt;p&gt;Thx&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Hi, Thank you for your help.&lt;/p&gt;
&lt;p&gt;I have now a further question. I only have one matrix : se00:=Matrix([[4,2,-1],[2,16,2],[-1,2,4]])&lt;/p&gt;
&lt;p&gt;I want to add them up as above. Here is what I did :&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;num:=16&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;ie0:=Matrix(33)&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&lt;strong&gt;for&lt;/strong&gt; m&lt;strong&gt; from&lt;/strong&gt; 1 &lt;strong&gt;to&lt;/strong&gt; num-1 &lt;strong&gt;do&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n1:=m*2+1:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ie0[n1..n1+2,n1..n1+2]:=se00&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt; end do&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Problem&amp;nbsp;: it does not give me a 33x33 matrix&lt;/p&gt;
&lt;p&gt;Please advice.&lt;/p&gt;
&lt;p&gt;Thx&lt;/p&gt;</description>
      <guid>130634</guid>
      <pubDate>Mon, 13 Feb 2012 22:15:25 Z</pubDate>
      <itunes:author>serena88</itunes:author>
      <author>serena88</author>
    </item>
    <item>
      <title>further example</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#comment130636</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally#comment130634"&gt;@serena88&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;restart:

se00:=Matrix([[4,2,-1],[2,16,2],[-1,2,4]]):

N:=LinearAlgebra:-RowDimension(se00);

number:=(33-1)/(N-1);

ie0:=Matrix(33):

for i from 1 to number do
   sz := (N-1)*(i-1)+1;
   ie0[sz..sz+N-1,sz..sz+N-1]:=ie0[sz..sz+N-1,sz..sz+N-1]+se00; # add corners
   ### ie0[sz..sz+N-1,sz..sz+N-1]:=se00; # overwrite corners
end do:

interface(rtablesize=33):

ie0;
&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally#comment130634"&gt;@serena88&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;restart:

se00:=Matrix([[4,2,-1],[2,16,2],[-1,2,4]]):

N:=LinearAlgebra:-RowDimension(se00);

number:=(33-1)/(N-1);

ie0:=Matrix(33):

for i from 1 to number do
   sz := (N-1)*(i-1)+1;
   ie0[sz..sz+N-1,sz..sz+N-1]:=ie0[sz..sz+N-1,sz..sz+N-1]+se00; # add corners
   ### ie0[sz..sz+N-1,sz..sz+N-1]:=se00; # overwrite corners
end do:

interface(rtablesize=33):

ie0;
&lt;/pre&gt;</description>
      <guid>130636</guid>
      <pubDate>Mon, 13 Feb 2012 22:31:48 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>How do i pick a value in the matrix?</title>
      <link>http://www.mapleprimes.com/questions/130382-Adding-Matrix-Diagonally?ref=Feed:MaplePrimes:Adding matrix diagonally:Comments#comment130712</link>
      <itunes:summary>&lt;p&gt;Hi, may I know how do i pick a value in the matrix to do further calculation please? for example, the matrix above, i would like the pick up the value in row 3 column 3 which is 32. Please advice. thanks&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Hi, may I know how do i pick a value in the matrix to do further calculation please? for example, the matrix above, i would like the pick up the value in row 3 column 3 which is 32. Please advice. thanks&lt;/p&gt;</description>
      <guid>130712</guid>
      <pubDate>Wed, 15 Feb 2012 17:06:07 Z</pubDate>
      <itunes:author>serena88</itunes:author>
      <author>serena88</author>
    </item>
  </channel>
</rss>