Carl Love

Carl Love

24855 Reputation

25 Badges

10 years, 122 days
Natick, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity

These are answers submitted by Carl Love

Unfortunately, the direction angles are measured in degrees.

Use e:= exp(1) somewhere in your code, preferably early. Otherwise, e is just an unassigned variable.

The generalized problem can be solved like this:

s:= {"a", "b", "c", "d", "e", "f"}:
B:= [3,3]: L:= ListTools:-PartialSums([0,B[]]): m:= nops(B):
    {seq}(s[[seq](j[1+L[k]..L[k+1]])], k= 1..m), 
    j= Iterator:-SetPartitionFixedSize(B)
             {{{"a", "b", "c"}, {"d", "e", "f"}}, 
               {{"a", "b", "d"}, {"c", "e", "f"}}, 
               {{"a", "b", "e"}, {"c", "d", "f"}}, 
               {{"a", "b", "f"}, {"c", "d", "e"}}, 
               {{"a", "c", "d"}, {"b", "e", "f"}}, 
               {{"a", "c", "e"}, {"b", "d", "f"}}, 
               {{"a", "c", "f"}, {"b", "d", "e"}}, 
               {{"a", "d", "e"}, {"b", "c", "f"}}, 
               {{"a", "d", "f"}, {"b", "c", "e"}}, 
               {{"a", "e", "f"}, {"b", "c", "d"}}}


The names that you use for the coordinate variables (such as rthetaphi) are irrelevant; you can use any names. The important thing is to use coords= spherical

You should use the command CodeTools:-Test.

One, and perhaps both, of your procedures contains indirect references to the parameters NN and MM. A procedure created with proc or -> cannot use indirect references to its parameters. Such procedures should be created with unapply instead:

cstr8:= unapply(G1 - FS, [NN, MM]);

You might need to do this with ATS also. From what you posted, I can't tell whether it has indirect references.

It can be done like this:

C:= <
    1, -0.5, 0.125, -2.449863383, 4.256426329, -1.826788463, 1.38888888e-3, 
    1.984126984e-4, 2.48015873e-5, 2.292633427e-4, -3.43791062e-5, -6.80212248e-5,
    4.06878271e-5, -5.03107054e-5, 3.795993196e-5, -1.28793671e-5, 1.752215748e-6,
Y:= unapply(C^%T.x^~<seq(0..17)>, x):
Y~([seq](0.0..1.0, 0.1));
 [1., 0.9492075127, 0.8916268943, 0.8251427077, 0.7534730280, 
   0.6839803183, 0.6254839642, 0.5860748693, 0.5709325210, 
   0.5801448253, 0.6065306590]

Of course, that doesn't match any column of the tables that you showed. No more can be said about that without seeing the original problem.

There are several possible interpretations of your problem. You said "a bunch of (x,y) coordinates". The first distinction that must be made is whether "a bunch" is 4 or more than 4. Possibly a second distinction must be made between one degree-3 polynomial or multiple degree-3 polynomials. All of these situations can be handled by 1 or 2 short Maple commands.

The interpretations:

1. You have exactly 4 points. This is the situation hinted at by Rouben's Answer. There is a unique polynomial of degree at most three that passes exactly through those points. The polynomial's coefficients can be determined by the process outlined by Rouben, or you can simply use the Maple command CurveFitting:-PolynomialInterpolation.

2. You have more than 4 points, but you know that you want a single degree-3 polynomial that goes through them all. This can't necessarily be done, but you can easily check whether it can. If it can be done, any subset of 4 of the points will give the same result (allowing some reasonable bounds for round-off error). Pick any 4, apply case 1, and see if the rest of the points fit.

3. You have more than 4 points, and you want the degree-3 polynomial that "best fits" all of them. The polynomial will not necessarily go exactly through any of the points; indeed, it's likely to not go through any exactly. This is called linear regression; the Maple command is Statistics:-LinearFit.

4. You have more than 4 points, and you want a smooth piecewise curve that goes exactly through them such that each "piece" is a polynomial of degree at most 3. This is called cubic spline interpolation; the Maple command is CurveFitting:-Spline.

Like this:


Edit: As pointed out by @mmcdara below, the above should be

plots:-display([entries(IP, nolist)])

Yes, the death of a kernel process due to a simple command with bad syntax is certainly a serious/critical bug. Since your printf command is syntactically nonsense, you should get a simple error message informing you of that.

I am writing this Answer to address your overall, titular Question, which is essentially about generalizing f@@n to situations where f takes many arguments and those arguments are changing for each application of f. Such generalizations are called folding f. You may read about it on help page ?fold; however, in this particular case I'm not going to use the commands foldr or foldl documented on that page but rather a new option to seq that does essentially the same thing more efficiently.

I am not writing this Answer because I think that folding is the best way to implement the particular situation that you present---the Answers by Kitonum and especially Acer have better methods for that situation. Nonetheless, your main Question is essentially about folding.

L:= "[(0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7),"
    " (7, 8), (8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14),"
    " (14, 15), (15, 16)]"
#L1 and L2 could be lists, but simple strings are enough in this case:   
L1:= "()[]": L2:= "{}{}":
X:= seq['fold'= (StringTools:-SubstituteAll, L)]('L1[i], L2[i]', i= 1..length(L1)); 
X := "{{0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5}, {4, 9}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {10, 11}, {11, 12}, {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"

This is more efficient than foldr or foldl because seq (ironically) does not create any sequence when used like this; it just feeds arguments to the accumulator procedure SubstituteAll. In contrast, using foldr or foldl requires first constructing the entire sequence of arguments before calling the command. 

Here's a constructor for the multiplicative group modulo n, regardless of whether n is prime:

#Constructor for the multiplicative group modulo n
MultGroup:= (n::And(posint, Not(1)))->
local G:= select(k-> igcd(n,k) = 1, [$n]), o:= nops(G), J:= table(G =~ [$o]);
            Matrix(o$2, (i,j)-> J[modp(G[i]*G[j], n)], shape= symmetric), 
            labels= G, check= false
        subs(_o= o, (k::integer[1.._o])-> G[k])
(g,G):= MultGroup(12);
    g, G := < a Cayley table group with 4 elements >, k-> G[k]

GroupTheory:-DrawCayleyTable(g, labels= G);

All you need is this:

ABC:= <
    -3,  1,  2;  # your A as a matrix row
    -2, -1,  1;  # ...  B ...
     0,  3, -3   # ...  C ...
alpha:= <2 | -1 | 1>:  # your weights as a row vector

The spacing and line breaks in the matrix input are only for enhanced readability. You could just as well enter it as

ABC:= <-3, 1, 2; -2, -1, 1; 0, 3, -3>:

Then all you need to type is


You asked:

  • Where can I see  in the lprint output that the first argument is of type uneval?

Since sqrt(x) is inherently unevaluated, you can't explicitly see that in this case. If you replace x by 4, then you'll see the difference.

  • Is sqrt(x) the first argument?

Yes. For any function f(a1, a2, ..., an)a1 is the first argument.

  • What does mi do?

It displays a variable in italic. All the Typesetting commands beginning with m are from the MathML language, and you can find them documented on numerous public websites.

1 2 3 4 5 6 7 Last Page 1 of 364