<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, if and for loops (nested)</title>
    <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested</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 16:20:13 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 16:20:13 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, if and for loops (nested)</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, if and for loops (nested)</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested</link>
    </image>
    <item>
      <title>I have</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#answer44499</link>
      <itunes:summary>&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;I have managed to make the loop work, except that for my first entry of the first loop where E[i]=E[2] I do not get given the correct answer. Can anyone see why it doesn't work as I have no idea? (running this again it gave me all correct entries, unsure why it failed first time as did not edit the code)&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;&lt;br /&gt;
for i from 2 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;a := abs(E[i]-E[1]);&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for j from 2 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if i &amp;lt;&amp;gt; j then&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;b := abs(E[i]-E[j])&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if b &amp;lt; a&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;then a := b&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;N := [op(N), a] end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for i to 1 do a := abs(E[i]-E[2]);&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for j from 3 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if i &amp;lt;&amp;gt; j then b := abs(E[i]-E[j])&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if b &amp;lt; a&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;then a := b&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;N := [op(N), a]&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end do;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also when I add the loop into my calculation, which is inside a loop&amp;nbsp;'to 500 do' I receive the message 'Error cannot determine if this expression is true or false b&amp;lt;2.9343729273....'&lt;/p&gt;
&lt;p&gt;which I don't understand as it will work when I remove the&amp;nbsp;loop around it. Clearly doing the calculations individually 500 times is ridiculously time consuming and unnecessary. Can you help?&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;I have managed to make the loop work, except that for my first entry of the first loop where E[i]=E[2] I do not get given the correct answer. Can anyone see why it doesn't work as I have no idea? (running this again it gave me all correct entries, unsure why it failed first time as did not edit the code)&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;&lt;br /&gt;
for i from 2 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;a := abs(E[i]-E[1]);&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for j from 2 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if i &amp;lt;&amp;gt; j then&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;b := abs(E[i]-E[j])&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if b &amp;lt; a&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;then a := b&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;N := [op(N), a] end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for i to 1 do a := abs(E[i]-E[2]);&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;for j from 3 to n do&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if i &amp;lt;&amp;gt; j then b := abs(E[i]-E[j])&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;if b &amp;lt; a&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;then a := b&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end if end do;&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;N := [op(N), a]&lt;/p&gt;
&lt;p&gt;&lt;maple&gt;&lt;/maple&gt;&lt;maple&gt;&lt;/maple&gt;end do;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also when I add the loop into my calculation, which is inside a loop&amp;nbsp;'to 500 do' I receive the message 'Error cannot determine if this expression is true or false b&amp;lt;2.9343729273....'&lt;/p&gt;
&lt;p&gt;which I don't understand as it will work when I remove the&amp;nbsp;loop around it. Clearly doing the calculations individually 500 times is ridiculously time consuming and unnecessary. Can you help?&lt;/p&gt;</description>
      <guid>44499</guid>
      <pubDate>Sat, 27 Feb 2010 19:47:55 Z</pubDate>
      <itunes:author>plummie</itunes:author>
      <author>plummie</author>
    </item>
    <item>
      <title>minimum difference</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#answer44500</link>
      <itunes:summary>&lt;p&gt;If the elements are real, a more efficient technique is to first sort them, then select the minimum adjacent difference:&lt;/p&gt;
&lt;pre&gt;
smallestRealDiff := proc(L :: list)
local sL;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sL := sort(L);
&amp;nbsp;&amp;nbsp;&amp;nbsp; min(sL[2..] - sL[..-2])
end proc:&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;If the elements are real, a more efficient technique is to first sort them, then select the minimum adjacent difference:&lt;/p&gt;
&lt;pre&gt;
smallestRealDiff := proc(L :: list)
local sL;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sL := sort(L);
&amp;nbsp;&amp;nbsp;&amp;nbsp; min(sL[2..] - sL[..-2])
end proc:&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <guid>44500</guid>
      <pubDate>Sat, 27 Feb 2010 21:21:21 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>I'm trying to find the</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#answer44503</link>
      <itunes:summary>&lt;p&gt;I'm trying to find the minimum distance between two e'values of an nxn matrix. ie. for each e'value E[1]....E[n]&amp;nbsp;i need to work out which other e'value it is closest to and then put the distance in a list.&lt;/p&gt;
&lt;p&gt;like so:&lt;br /&gt;
N:= [abs(E[1]-E[5]),abs(E[2]-E[21]),abs(E[3]-E[7]),.....etc&lt;/p&gt;
&lt;p&gt;This final list N is made up of values from 500+ nxn matrices so that i able to evaluate them statistically. I'm just using the op(N) call to put them all together&lt;/p&gt;
&lt;p&gt;So really I am looking for a mindiff but for each e'value.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I'm trying to find the minimum distance between two e'values of an nxn matrix. ie. for each e'value E[1]....E[n]&amp;nbsp;i need to work out which other e'value it is closest to and then put the distance in a list.&lt;/p&gt;
&lt;p&gt;like so:&lt;br /&gt;
N:= [abs(E[1]-E[5]),abs(E[2]-E[21]),abs(E[3]-E[7]),.....etc&lt;/p&gt;
&lt;p&gt;This final list N is made up of values from 500+ nxn matrices so that i able to evaluate them statistically. I'm just using the op(N) call to put them all together&lt;/p&gt;
&lt;p&gt;So really I am looking for a mindiff but for each e'value.&lt;/p&gt;</description>
      <guid>44503</guid>
      <pubDate>Sun, 28 Feb 2010 14:58:49 Z</pubDate>
      <itunes:author>plummie</itunes:author>
      <author>plummie</author>
    </item>
    <item>
      <title>possibilities</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#answer44505</link>
      <itunes:summary>&lt;p&gt;That helps, but I'm still not sure I understand.&amp;nbsp; That is, if E is an nxn matrix, why are you accessing it with one index (E[i])?&lt;/p&gt;
&lt;p&gt;I'm going to assume that E is actually a list.&amp;nbsp; Here are two implementation, which may or may not do what you want.&amp;nbsp; The first is a straightforward implementation of your original idea (as I understand it), but using seqs.&amp;nbsp; The algorithm is not particularly efficient.&amp;nbsp; The second procedure uses a method I described &lt;a href="http://www.mapleprimes.com/blog/joeriel/sortingpermutationlist"&gt;here&lt;/a&gt; to first create a permutation list that is used to sort the list.&amp;nbsp; That permits looking at adjacent values to find the minimum, which significantly improves the speed.&amp;nbsp; After computing the values, it applies the inverse permutation to return the final list in the desired order.&lt;/p&gt;
&lt;pre&gt;
slow := proc(E :: list)
local i,j,n;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n := nops(E);
&amp;nbsp;&amp;nbsp;&amp;nbsp; [seq(min(seq(abs(E[i]-E[j]),j=1..i-1),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seq(abs(E[i]-E[j]),j=i+i..n)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , i = 1..n)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ];
end proc:

fast := proc(E :: list(numeric))
local i, n, P, L, A;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n := nops(E);
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute permutation that sorts E
&amp;nbsp;&amp;nbsp;&amp;nbsp; P := map(attributes, sort([seq(setattribute(SFloat(E[i]),i), i=1..n)]));
&amp;nbsp;&amp;nbsp;&amp;nbsp; # apply permutation to sort E
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := [seq(E[i], i in P)];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute adjacent differences
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := L[2..] - L[..-2];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute minimum adjacencies
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := [L[1], seq(min(L[i],L[i+1]), i=1..n-2), L[n-1]];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # apply inverse permutation to restore order
&amp;nbsp;&amp;nbsp;&amp;nbsp; A := Array(1..n);
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i to n do
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A[P[i]] := L[i];
&amp;nbsp;&amp;nbsp;&amp;nbsp; end do;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [seq(A[i], i=1..n)];
end proc:

n := 1000:
L := RandomTools:-Generate(list(integer(range=0..5),n)):
time(slow(L));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.504

time(fast(L));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.008

&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;That helps, but I'm still not sure I understand.&amp;nbsp; That is, if E is an nxn matrix, why are you accessing it with one index (E[i])?&lt;/p&gt;
&lt;p&gt;I'm going to assume that E is actually a list.&amp;nbsp; Here are two implementation, which may or may not do what you want.&amp;nbsp; The first is a straightforward implementation of your original idea (as I understand it), but using seqs.&amp;nbsp; The algorithm is not particularly efficient.&amp;nbsp; The second procedure uses a method I described &lt;a href="http://www.mapleprimes.com/blog/joeriel/sortingpermutationlist"&gt;here&lt;/a&gt; to first create a permutation list that is used to sort the list.&amp;nbsp; That permits looking at adjacent values to find the minimum, which significantly improves the speed.&amp;nbsp; After computing the values, it applies the inverse permutation to return the final list in the desired order.&lt;/p&gt;
&lt;pre&gt;
slow := proc(E :: list)
local i,j,n;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n := nops(E);
&amp;nbsp;&amp;nbsp;&amp;nbsp; [seq(min(seq(abs(E[i]-E[j]),j=1..i-1),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seq(abs(E[i]-E[j]),j=i+i..n)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , i = 1..n)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ];
end proc:

fast := proc(E :: list(numeric))
local i, n, P, L, A;
&amp;nbsp;&amp;nbsp;&amp;nbsp; n := nops(E);
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute permutation that sorts E
&amp;nbsp;&amp;nbsp;&amp;nbsp; P := map(attributes, sort([seq(setattribute(SFloat(E[i]),i), i=1..n)]));
&amp;nbsp;&amp;nbsp;&amp;nbsp; # apply permutation to sort E
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := [seq(E[i], i in P)];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute adjacent differences
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := L[2..] - L[..-2];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compute minimum adjacencies
&amp;nbsp;&amp;nbsp;&amp;nbsp; L := [L[1], seq(min(L[i],L[i+1]), i=1..n-2), L[n-1]];
&amp;nbsp;&amp;nbsp;&amp;nbsp; # apply inverse permutation to restore order
&amp;nbsp;&amp;nbsp;&amp;nbsp; A := Array(1..n);
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i to n do
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A[P[i]] := L[i];
&amp;nbsp;&amp;nbsp;&amp;nbsp; end do;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [seq(A[i], i=1..n)];
end proc:

n := 1000:
L := RandomTools:-Generate(list(integer(range=0..5),n)):
time(slow(L));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.504

time(fast(L));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.008

&lt;/pre&gt;</description>
      <guid>44505</guid>
      <pubDate>Sun, 28 Feb 2010 22:35:45 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>do I understand it correctly?</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#answer44725</link>
      <itunes:summary>&lt;p&gt;&lt;i&gt;I'm trying to find the minimum distance between two e'values of an nxn  matrix&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Then I would do it by sorting (as already discussed), take 1st absolute&lt;br /&gt;
differences and sort again. The first element is one minimal solution:&lt;/p&gt;
&lt;pre&gt;

M:=LinearAlgebra[RandomMatrix](3,3,generator=-99..99): # to have an example

V:=convert(M, Vector[row]);
V:=sort(V);

d:=LinearAlgebra[Dimension](V);

f:= (j) -&amp;gt; abs(V[j]-V[j+1]); # you want the minimum, if applied to V
W:=Vector[row](d-1,f);
W:=sort(W);
W[1];
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
In case used memory is a concern:&lt;br /&gt;
&lt;br /&gt;
While it is easy to re-use W (by using 'map') if the dimension is constant&lt;br /&gt;
for V one would have to ponder a bit (but there is some command for a fast&lt;br /&gt;
re-arrangement of memory, if I recall correctly).&lt;br /&gt;
&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;i&gt;I'm trying to find the minimum distance between two e'values of an nxn  matrix&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Then I would do it by sorting (as already discussed), take 1st absolute&lt;br /&gt;
differences and sort again. The first element is one minimal solution:&lt;/p&gt;
&lt;pre&gt;

M:=LinearAlgebra[RandomMatrix](3,3,generator=-99..99): # to have an example

V:=convert(M, Vector[row]);
V:=sort(V);

d:=LinearAlgebra[Dimension](V);

f:= (j) -&amp;gt; abs(V[j]-V[j+1]); # you want the minimum, if applied to V
W:=Vector[row](d-1,f);
W:=sort(W);
W[1];
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
In case used memory is a concern:&lt;br /&gt;
&lt;br /&gt;
While it is easy to re-use W (by using 'map') if the dimension is constant&lt;br /&gt;
for V one would have to ponder a bit (but there is some command for a fast&lt;br /&gt;
re-arrangement of memory, if I recall correctly).&lt;br /&gt;
&amp;nbsp;&lt;/p&gt;</description>
      <guid>44725</guid>
      <pubDate>Mon, 01 Mar 2010 01:09:35 Z</pubDate>
      <itunes:author>Axel Vogt</itunes:author>
      <author>Axel Vogt</author>
    </item>
    <item>
      <title>though that sounds like it</title>
      <link>http://www.mapleprimes.com/questions/35624-If-And-For-Loops-nested?ref=Feed:MaplePrimes:if and for loops (nested):Comments#comment44501</link>
      <itunes:summary>&lt;p&gt;though that sounds like it would be a great idea. I'm not sure how I could implement it as I would have to generate new lists for each i from 1 to n, then put the result of smallestRealDiff into a new list.&lt;/p&gt;
&lt;p&gt;I don't think that when I'm generating things for upto i=200 this would work very well as I'd have to write a load of new loops around it and I think that would confuse me more.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;though that sounds like it would be a great idea. I'm not sure how I could implement it as I would have to generate new lists for each i from 1 to n, then put the result of smallestRealDiff into a new list.&lt;/p&gt;
&lt;p&gt;I don't think that when I'm generating things for upto i=200 this would work very well as I'd have to write a load of new loops around it and I think that would confuse me more.&lt;/p&gt;</description>
      <guid>44501</guid>
      <pubDate>Sat, 27 Feb 2010 22:19:39 Z</pubDate>
      <itunes:author>plummie</itunes:author>
      <author>plummie</author>
    </item>
  </channel>
</rss>