Carl Love

## 26827 Reputation

11 years, 278 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

## local plot...

In Maple 17, put the following in your .ini file:

local plot:= proc({discont::truefalse:= true}) :-plot(args, :-discont= discont) end proc:

(I updated this Answer so that now you can pass discont= false to plot if you want. Essentially, this is changing the default value of discont from false to true.)

If you don't have Maple 17, let me know: Essentially same thing can be done a bit more hackishly in earlier Maple.

## Dividing combinations into manageable ch...

@wkehowski Yes, I see the problem: Using combinat:-nextcomb is inherently sequential (i.e., not parallel) (the "next" in the name pretty much guarantees that!). You have way too many combinations to generate them all, store in memory, and then apply Threads:-Map or Threads:-Seq.

Here's an idea: Find a number of combinations that your memory can comfortably hold---let's say 1 million.

while not
done do
L:= the next million combinations as a list;
;

write GoodPts to a file
end do;

Select:= proc(x ::
a candidate point)
if x
is a point that you want to save then x else NULL end if
end proc;

It would be more efficient to not use nextcomb to generate the L.  I'll make up a fully coded example later this evening, I think.

## combinat:-cartprod...

Kitonum's triple-loop solution is difficult to generalize to an arbitrary number of lists. And building lists (or sets, sequences, etc.) by appending onto the end of an existing list is a bad (inefficient) habit that you would be better off not starting. To handle an arbitrary number of sets, use ?combinat,cartprod . To build a list in a loop, store the items in a ?table temporarily and then use ?convert,list .

The following code builds the list of combinations that you want:

restart:
Iter:= combinat:-cartprod([seq](combinat:-permute(3,k), k= [3,2,1])):
Perms:= table():  k:= 0:
while not Iter[finished] do k:= k+1; Perms[k]:= Iter[nextvalue]() end do:
convert(Perms, list);

## MatrixInverse...

It's MatrixInverse (with capital I), not Matrixinverse.

## numpoints= 10000...

In addition to Kitonum's Answer, numpoints = 10 seems much too low. The system can easily handle 10,000points (100 x 100 grid).

It is much, much easier to just use ?Threads,Map or ?Threads,Seq rather than Task. Let Maple worry about how many pieces to break it into.

## Putting it in simple English: You can't ...

Putting it in simple English: You can't Continue what you didn't Start.

## Don't use loop index as a symbolic...

Your code doesn't work because you are trying to use the variables c, d, and e as both symbolics (variables without an assigned value) and as loop indices (the variables after for). You need to use different variables and then subs one for the other within the loop, like this:

N := [];
for _c in poss_for_v(1) do
for _d in poss_for_v(2) do
for _e in poss_for_v(3) do
N := [op(N), subs([c= _c, d= _d, e= _e, M[6])]
od
od
od:

(The code above is only meant to correct your primary problem and does not represent my opinion as to the best way to perform the operation. For the best way, see ?combinat,cartprod and store the results in a ?table , not a list, and ?convert,list the table to a list when the loop is finished.)

## for i in ... do...

You can avoid the need (and expense) of a conditional evaluation at every loop iteration by using the in form of for. For the example at hand, the code would be

for i in \$1..2, \$4..8 do
print(i)
end do;

## Symbolic geom3d example...

It can be used symbolically. Here's an example:

restart:
with(geom3d):
assume(a<>d):
point(X, a, b, c):
point(Y, d, e, f):
line(L, [X, Y]):
Equation(L, t);
[a + (d - a) t, b + (e - b) t, c + (f - c) t]

## Extract max from the original plot...

You can extract the maximum function value from the original plot and use it to modify that plot like this:

f:= randpoly(x);
P:= plot(f, x= -10..10);
A:= op([1,1], P);  #The curve's point matrix
F:= A[.., 2];  #The function values
m:= max(F);
subsindets(P, Matrix, A-> < A[.., 1] | F /~ m >);

## Okay in Maple 17...

I do not get the warning in Maple 17.01/64 (Windows 8). I just get 10 solutions. What version of Maple are you using? I've attached my execution of your worksheet. So, if you got 10 solutions in your Maple, I guess that no solutions were actually lost.

## op(2, eval(T))...

If T is a table, then op(2, eval(T)) will return the list of equations "inside" T. With that knowledge, we can write a one-line procedure to merge any number of tables:

merge_tables:= ()->
table(map((T::table)-> op(2, eval(T))[], [args]))
;

To apply it to your loop, you need to initialize T with T:= table():

sol[2] := [[2, 1], [3, 4]];
T:= table():
for i from 1 to nops(sol[2]) do
sol[2][i] := [seq(op(k,sol[2][i]), k=nops(sol[2][i])..1, -1)];
T:= merge_tables(
T,
table([
seq(op(k,sol[2][i])=op(k-1,sol[2][i]), k=2..nops(sol[2][i])),
op(1,sol[2][i])=op(nops(sol[2][i]),sol[2][i])
])
)
od;

I must say though that this is a very inefficient process (O(n^2)), as is any iterative concatenation. I understand what you are trying to do is convert a permutation from disjoint cycle form (disjcyc) into table form. It is better to create one table as a "seq of seqs" rather than using concatenation. I do this in the procedure in the Reply below.

Note that the fixed points are not represented in disjcyc, so the converter needs to be told the highest number (since it may be a fixed point), which is called the degree of the permutation. You can default the degree to the highest number that appears in the disjcyc, which is what I do in the procedure below.

## := vs. =...

You are mixing up the assignment operator := with the equality operator =. The code sample that you gave could not possibly work like you said because the parser will immediatey reject a statement beginning if a:= with the message "Error, `:=` unexpected."

You can have any number of statements between the then and elif, else, or end if as long as they are separated with colons or semicolons.

if a = 3 then   # = not :=
b:= 4;
c:= 2032;
h:= 7
elif a = 4 then
b:= 5;  c:= 1003;  h:= 42
else
b, c, h:= 7, 25, 62
end if;

After the else I've shown a multiple assignment statement.

## eliminate...

I doubt that the Asker was looking for any solution with r^4 appearing on the right side.

I prefer to use eliminate over isolate when possible. It handles multiple solutions nicely.

 > restart:
 > eq1:= (r^2*sin(t)^2+r^2*cos(t)^2)^2 = a^2*(r^2*cos(t)^2-r^2*sin(t)^2):
 > eq2:= algsubs(r^2= R, eq1);

Regular subs would have worked in this very particular case, but not on an expanded version.

 > Sol:= eliminate({eq2}, R);

 > eq3:= subs(R= r^2, Sol[2][1][]);

 > eq4:= combine(%);

 >