<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, programming issue</title>
    <link>http://www.mapleprimes.com/questions/142844-Programming-Issue</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 09:27:46 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 09:27:46 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, programming issue</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, programming issue</title>
      <link>http://www.mapleprimes.com/questions/142844-Programming-Issue</link>
    </image>
    <item>
      <title>copy, ArrayTools, and ?rtable_indexing</title>
      <link>http://www.mapleprimes.com/questions/142844-Programming-Issue?ref=Feed:MaplePrimes:programming issue:Comments#answer142848</link>
      <itunes:summary>&lt;p&gt;First off, please do not use the old lowercase constructor commands&lt;strong&gt; matrix&lt;/strong&gt;, &lt;strong&gt;array&lt;/strong&gt;, &lt;strong&gt;vector&lt;/strong&gt;. The new constructors are capitalized---&lt;strong&gt;Matrix&lt;/strong&gt;, &lt;strong&gt;Array&lt;/strong&gt;, &lt;strong&gt;Vector&lt;/strong&gt;---and they are much more efficient and versatile. I will not help you anymore if you continue to use the lowercase constructors, as I'd rather just forget about them. The rest of this post will deal strictly with the newer versions. Also, anything that I say below about Arrays could equally well be said about Matrices or Vectors.&lt;/p&gt;
&lt;p&gt;You wrote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;for l to 5 do: for i to 6 do: for j to 6 do: L[i,j] := P[i,j,l]: od: od: V[l]:=L: od:&lt;br&gt;The code fails in that V[1]=V[2]=...v[5] = P[i,j,5].&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The immediate problem is that &lt;strong&gt;V[l]:= L&lt;/strong&gt; needs to be &lt;strong&gt;V[l]:= copy(L)&lt;/strong&gt;; however, assigning individual entries in a loop is an inefficient way to do this (see below for a more efficient way). The reason the &lt;strong&gt;copy&lt;/strong&gt; is needed is a somewhat arcane topic. You can read some about it at &lt;a href="http://www.maplesoft.com/support/help/search.aspx?term=copy,"&gt;?copy,&lt;/a&gt; but the topic requires a moderate amount of computer programming knowledge to understand. The take-away is &lt;em&gt;Don't directly assign one Array to another (unless you understand the consequences); it does not make an independent copy of the Array.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt; There are many commands in the &lt;a href='http://www.maplesoft.com/support/help/search.aspx?term=ArrayTools' target='_new'&gt;?ArrayTools&lt;/a&gt; package for efficiently handling things like changing dimensions, copying parts of Arrays, etc.&lt;/p&gt;
&lt;p&gt;You wrote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;Also, given a matrix, is there a way to extract a column vector from that matrix? I.e. in FORTAN is M is a matrix, M(:,3) would &lt;a style="text-decoration: underline;" href="http://www.mapleprimes.com/questions/142844-Programming-Issue#"&gt;return&lt;/a&gt; the third column of M. Is there a similar command in Maple?&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;Yes, and the syntax is almost identical: &lt;strong&gt;M(.., 3) &lt;/strong&gt;or &lt;strong&gt;M[.., 3]&lt;/strong&gt;. The available combinations for selecting and rearranging subparts of Arrays is vast, and discussed at &lt;a href="http://www.maplesoft.com/support/help/search.aspx?term=rtable_indexing"&gt;?rtable_indexing&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;So, applying this subpart selecting to your original loop, you could do the whole job as&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;&lt;strong&gt;V:= Array(1..5, i-&amp;gt; P[.., .., i]);&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;</itunes:summary>
      <description>&lt;p&gt;First off, please do not use the old lowercase constructor commands&lt;strong&gt; matrix&lt;/strong&gt;, &lt;strong&gt;array&lt;/strong&gt;, &lt;strong&gt;vector&lt;/strong&gt;. The new constructors are capitalized---&lt;strong&gt;Matrix&lt;/strong&gt;, &lt;strong&gt;Array&lt;/strong&gt;, &lt;strong&gt;Vector&lt;/strong&gt;---and they are much more efficient and versatile. I will not help you anymore if you continue to use the lowercase constructors, as I'd rather just forget about them. The rest of this post will deal strictly with the newer versions. Also, anything that I say below about Arrays could equally well be said about Matrices or Vectors.&lt;/p&gt;
&lt;p&gt;You wrote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;for l to 5 do: for i to 6 do: for j to 6 do: L[i,j] := P[i,j,l]: od: od: V[l]:=L: od:&lt;br&gt;The code fails in that V[1]=V[2]=...v[5] = P[i,j,5].&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The immediate problem is that &lt;strong&gt;V[l]:= L&lt;/strong&gt; needs to be &lt;strong&gt;V[l]:= copy(L)&lt;/strong&gt;; however, assigning individual entries in a loop is an inefficient way to do this (see below for a more efficient way). The reason the &lt;strong&gt;copy&lt;/strong&gt; is needed is a somewhat arcane topic. You can read some about it at &lt;a href="http://www.maplesoft.com/support/help/search.aspx?term=copy,"&gt;?copy,&lt;/a&gt; but the topic requires a moderate amount of computer programming knowledge to understand. The take-away is &lt;em&gt;Don't directly assign one Array to another (unless you understand the consequences); it does not make an independent copy of the Array.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt; There are many commands in the &lt;a href='http://www.maplesoft.com/support/help/search.aspx?term=ArrayTools' target='_new'&gt;?ArrayTools&lt;/a&gt; package for efficiently handling things like changing dimensions, copying parts of Arrays, etc.&lt;/p&gt;
&lt;p&gt;You wrote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;Also, given a matrix, is there a way to extract a column vector from that matrix? I.e. in FORTAN is M is a matrix, M(:,3) would &lt;a style="text-decoration: underline;" href="http://www.mapleprimes.com/questions/142844-Programming-Issue#"&gt;return&lt;/a&gt; the third column of M. Is there a similar command in Maple?&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;Yes, and the syntax is almost identical: &lt;strong&gt;M(.., 3) &lt;/strong&gt;or &lt;strong&gt;M[.., 3]&lt;/strong&gt;. The available combinations for selecting and rearranging subparts of Arrays is vast, and discussed at &lt;a href="http://www.maplesoft.com/support/help/search.aspx?term=rtable_indexing"&gt;?rtable_indexing&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;So, applying this subpart selecting to your original loop, you could do the whole job as&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;&lt;strong&gt;V:= Array(1..5, i-&amp;gt; P[.., .., i]);&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="mainBody document"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;</description>
      <guid>142848</guid>
      <pubDate>Thu, 31 Jan 2013 05:21:43 Z</pubDate>
      <itunes:author>Carl Love</itunes:author>
      <author>Carl Love</author>
    </item>
    <item>
      <title>Try this</title>
      <link>http://www.mapleprimes.com/questions/142844-Programming-Issue?ref=Feed:MaplePrimes:programming issue:Comments#answer142849</link>
      <itunes:summary>&lt;p&gt;restart;&lt;br&gt;P:=Array(1..6,1..6,1..5,(i,j,k)-&amp;gt;i*j*10^k); #Example&lt;br&gt;&lt;br&gt;P[1..6,1..6,1];&lt;br&gt;Array([seq(P[1..6,1..6,i],i=1..5)]);&lt;br&gt;&lt;br&gt;#Your code just needs 'copy':&lt;br&gt;L:= Matrix(1..6,1..6):&lt;br&gt;&lt;br&gt;V:=Array(1..5):&lt;br&gt;&lt;br&gt;for l to 5 do &lt;br&gt;&amp;nbsp; for i to 6 do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j to 6 do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; L[i,j] := P[i,j,l] &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; od &lt;br&gt;&amp;nbsp; od; &lt;br&gt;&amp;nbsp; V[l]:=copy(L) &lt;br&gt;od:&lt;br&gt;&lt;br&gt;V;&lt;br&gt;&lt;br&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;restart;&lt;br&gt;P:=Array(1..6,1..6,1..5,(i,j,k)-&amp;gt;i*j*10^k); #Example&lt;br&gt;&lt;br&gt;P[1..6,1..6,1];&lt;br&gt;Array([seq(P[1..6,1..6,i],i=1..5)]);&lt;br&gt;&lt;br&gt;#Your code just needs 'copy':&lt;br&gt;L:= Matrix(1..6,1..6):&lt;br&gt;&lt;br&gt;V:=Array(1..5):&lt;br&gt;&lt;br&gt;for l to 5 do &lt;br&gt;&amp;nbsp; for i to 6 do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j to 6 do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; L[i,j] := P[i,j,l] &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; od &lt;br&gt;&amp;nbsp; od; &lt;br&gt;&amp;nbsp; V[l]:=copy(L) &lt;br&gt;od:&lt;br&gt;&lt;br&gt;V;&lt;br&gt;&lt;br&gt;&lt;/p&gt;</description>
      <guid>142849</guid>
      <pubDate>Thu, 31 Jan 2013 05:40:15 Z</pubDate>
      <itunes:author>Preben Alsholm</itunes:author>
      <author>Preben Alsholm</author>
    </item>
    <item>
      <title>subtype</title>
      <link>http://www.mapleprimes.com/questions/142844-Programming-Issue?ref=Feed:MaplePrimes:programming issue:Comments#comment142851</link>
      <itunes:summary>&lt;p&gt;As written, the 2-dimensional rtable entries of V are of type Array rather than of type Matrix. It's not clear from the original post which is wanted or needed, and perhaps it won't matter. But for some uses it will matter, eg. behaviour w.r.t. the `.` operator, or in a release before Maple 16 when the LinearAlgebra package got&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=updates/Maple16/coercion"&gt;coercion&lt;/a&gt;, etc. If it matters, then this aspect can be efficiently toggled in-place on the V[i], ie.&lt;/p&gt;
&lt;pre&gt;for i from 1 to 5 do rtable_options(V[i],subtype=Matrix); end do:
&lt;/pre&gt;
&lt;p&gt;After doing so V[i] will be a Matrix instead of a 2-dimensional Array, and V[i][..,k] will be a column Vector instead of a 1-dimensional Array.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;As written, the 2-dimensional rtable entries of V are of type Array rather than of type Matrix. It's not clear from the original post which is wanted or needed, and perhaps it won't matter. But for some uses it will matter, eg. behaviour w.r.t. the `.` operator, or in a release before Maple 16 when the LinearAlgebra package got&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=updates/Maple16/coercion"&gt;coercion&lt;/a&gt;, etc. If it matters, then this aspect can be efficiently toggled in-place on the V[i], ie.&lt;/p&gt;
&lt;pre&gt;for i from 1 to 5 do rtable_options(V[i],subtype=Matrix); end do:
&lt;/pre&gt;
&lt;p&gt;After doing so V[i] will be a Matrix instead of a 2-dimensional Array, and V[i][..,k] will be a column Vector instead of a 1-dimensional Array.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>142851</guid>
      <pubDate>Thu, 31 Jan 2013 08:11:15 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>Alternatively</title>
      <link>http://www.mapleprimes.com/questions/142844-Programming-Issue?ref=Feed:MaplePrimes:programming issue:Comments#comment142852</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/142844-Programming-Issue#comment142851"&gt;@acer&lt;/a&gt; That seems esoteric, though an inplace conversion is handy. Clearer, at least to me, is&lt;/p&gt;
&lt;pre&gt;V:= Array(1..5, i-&amp;gt; Matrix(P[.., .., i]));&lt;br&gt;&lt;br&gt;&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/142844-Programming-Issue#comment142851"&gt;@acer&lt;/a&gt; That seems esoteric, though an inplace conversion is handy. Clearer, at least to me, is&lt;/p&gt;
&lt;pre&gt;V:= Array(1..5, i-&amp;gt; Matrix(P[.., .., i]));&lt;br&gt;&lt;br&gt;&lt;/pre&gt;</description>
      <guid>142852</guid>
      <pubDate>Thu, 31 Jan 2013 09:49:13 Z</pubDate>
      <itunes:author>Joe Riel</itunes:author>
      <author>Joe Riel</author>
    </item>
  </channel>
</rss>