<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, Matrix Construction Functions Seem Very Slow</title>
    <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Wed, 10 Jun 2026 17:15:14 GMT</lastBuildDate>
    <pubDate>Wed, 10 Jun 2026 17:15:14 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, Matrix Construction Functions Seem Very Slow</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow</link>
    </image>
    <item>
      <title>please post (small) examples</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow?ref=Feed:MaplePrimes:Matrix Construction Functions Seem Very Slow:Comments#comment79878</link>
      <itunes:summary>There are several ways to do stacking and augmenting of Matrices and Vectors, some of which might depend on the type of data.

If you could supply some (small, but fully detailed) examples of what you are trying to accomplish then it would be easier to make suggestions as to efficient ways to do it.

Another useful piece of information is whether you would be content with a result that contained only (possibly complex) floating-point data.

Thanks very much,
Dave Linder
Team Lead, Mathematical Software, Maplesoft, Inc.
</itunes:summary>
      <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
      <guid>79878</guid>
      <pubDate>Thu, 11 May 2006 01:33:38 Z</pubDate>
      <itunes:author>Dave L</itunes:author>
      <author>Dave L</author>
    </item>
    <item>
      <title>The Matrix constructor is slow</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow?ref=Feed:MaplePrimes:Matrix Construction Functions Seem Very Slow:Comments#comment79877</link>
      <itunes:summary>The Matrix constructor is known to be slow.  In this case it creates a rather expensive initialization procedure which is called for each entry of the result.  You can see what I mean in the following example:

A := Matrix([[1,2],[3,4]]);
B := Matrix([[5,6],[7,8]]);
trace(Matrix);
Matrix([A,B]);

If you look closely at that initializer, you will see that it evaluates the submatrices.  This happens for each index (i,j) in the result.</itunes:summary>
      <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
      <guid>79877</guid>
      <pubDate>Thu, 11 May 2006 02:31:31 Z</pubDate>
      <itunes:author>roman_pearce</itunes:author>
      <author>roman_pearce</author>
    </item>
    <item>
      <title>Here is what I am trying to do:</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow?ref=Feed:MaplePrimes:Matrix Construction Functions Seem Very Slow:Comments#comment86515</link>
      <itunes:summary>First of all thank you both very much for your input.

Basically what I am trying to do is to combine four square matrices, usually, of order ~ 256x256 into one ~512x512 matrix (although sometimes I just need to stack two of these together, but in general I do the first thing). The reason for doing this is that I have written an optical modelling code that requires me to construct the initial smaller matrices which represent individual electric and magnetic field boundary conditions. I then want to do simple matrix operations on the resulting matrices, nothing particularly extreme just simple addition and multiplication as well as solving Ax=b using LinearSolve, in order to match these conditions. I have tried writing simple for loops that copy the individual [i,j] entries across into a pre-initialized larger matrix, although this is slightly quicker it still seems to take an inordinate amount of time. If there is a better way of combining them or if my calculations can be done without combining the matrices at all then that would certainly speed things up.

My result would indeed only contain floating point numbers although as I mentioned they would definitely be complex and often beyond hardware precision and exponent.

Thank you again,

Martyn</itunes:summary>
      <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
      <guid>86515</guid>
      <pubDate>Thu, 11 May 2006 14:05:57 Z</pubDate>
      <itunes:author>py9mrg</itunes:author>
      <author>py9mrg</author>
    </item>
    <item>
      <title>Something to try ...</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow?ref=Feed:MaplePrimes:Matrix Construction Functions Seem Very Slow:Comments#comment90676</link>
      <itunes:summary>You can try the following:
&lt;tt&gt;
My := Matrix(512,512):
My[1..256,1..256] := M1:
My[1..256,257..512] := M2:
My[257..512,1..256] := M3:
My[257..512,257..512] := M4:
&lt;/tt&gt;

This creates the target matrix and then just copies the entries over without evaluation.

Here is a complete test case:

Create test matrices:
&lt;tt&gt;
M1 := LinearAlgebra:-RandomMatrix(256,256);
M2 := LinearAlgebra:-RandomMatrix(256,256);
M3 := LinearAlgebra:-RandomMatrix(256,256);
M4 := LinearAlgebra:-RandomMatrix(256,256);
&lt;/tt&gt;

This takes about 40 seconds on my computer:
&lt;tt&gt;
st:=time():
Mx := &amp;lt;&amp;lt;M1|M2&amp;gt;,&amp;lt;M3|M4&amp;gt;&amp;gt;;
time()-st;
&lt;/tt&gt;

This takes less than a second on my computer:
&lt;tt&gt;
st := time():
My := Matrix(512,512):
My[1..256,1..256] := M1:
My[1..256,257..512] := M2:
My[257..512,1..256] := M3:
My[257..512,257..512] := M4:
time()-st;
&lt;/tt&gt;

Check that both techniques produce the same matrix:
&lt;tt&gt;
LinearAlgebra:-Norm(Mx-My);
&lt;/tt&gt;




Jan Bakus
Applications Engineer, Maplesoft</itunes:summary>
      <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
      <guid>90676</guid>
      <pubDate>Thu, 11 May 2006 18:56:10 Z</pubDate>
      <itunes:author>jan</itunes:author>
      <author>jan</author>
    </item>
    <item>
      <title>Thank you!</title>
      <link>http://www.mapleprimes.com/posts/42871-Matrix-Construction-Functions-Seem-Very-Slow?ref=Feed:MaplePrimes:Matrix Construction Functions Seem Very Slow:Comments#comment90677</link>
      <itunes:summary>Thank you very very much for that. It has speeded up those processes incredibly, and as a result my model now runs much much much faster than it did!

Thank you again.

Martyn</itunes:summary>
      <description>The latest comments added to the Post, Matrix Construction Functions Seem Very Slow</description>
      <guid>90677</guid>
      <pubDate>Thu, 11 May 2006 21:53:49 Z</pubDate>
      <itunes:author>py9mrg</itunes:author>
      <author>py9mrg</author>
    </item>
  </channel>
</rss>