Carl Love

Carl Love

26827 Reputation

25 Badges

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

MaplePrimes Activity

These are answers submitted by Carl Love

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.

@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;
      GoodPts:= Threads:-Map(Select, L)

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.

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:

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);

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

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 Continue what you didn't Start.

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])]

(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.)

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
end do;

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

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]

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 >);

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.


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(
               seq(op(k,sol[2][i])=op(k-1,sol[2][i]), k=2..nops(sol[2][i])),

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.

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
     b, c, h:= 7, 25, 62
end if;

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

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.


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);

(sin(t)^2*R+cos(t)^2*R)^2 = a^2*(-sin(t)^2*R+cos(t)^2*R)

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


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

[{R = 0}, {}], [{R = 2*cos(t)^2*a^2-a^2}, {}]

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

r^2 = 2*cos(t)^2*a^2-a^2

eq4:= combine(%);

r^2 = a^2*cos(2*t)



First 350 351 352 353 354 355 356 Last Page 352 of 385