Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 319 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

As far as I can tell, the convention is that when any Maple command returns a global name whose form has not been specified by the user, that name begins with an underscore _. The example that you show does follow that convention. If you find any command that deviates from that convention, it would be worth posting about it. The names beginning with underscore in any expression e can be extracted by

indets(e, suffixed(_));

What makes you think that your command  didn't work? The number returned by Export is the number of bytes written to the file.

Here's another way:

restart:
T:= table(sparse):
#Recast the permutation vector as a 3x3 matrix:
pm:= ArrayTools:-Alias(output((P:= Iterator:-Permute(1..9))), 0, [1..3, 1..3]):

#Then conversion to base-10 and summing can be done as a single vector-matrix-vector 
#product:
(o,t):= (<1|1|1>, <100, 10, 1>):
in P do T[(v:= o.pm.t)]:= T[v]+1 od:

#Group each number of occurences by the sums that attain it:
sort(
   [indices((lhs~)~(ListTools:-Classify(rhs, [indices(T, 'pairs')])), 'pairs')], 
   'key'= -lhs
);

#This is useful for further analysis:
X:= Statistics:-RandomVariable(
   EmpiricalDistribution(
      [indices(T, 'nolist')], 'probabilities'= [entries(T, 'nolist')]/~9!
   )
):

Statistics:-DensityPlot(X);

This shows both an early stage of convergence via the Central Limit Theorem and an amazing fractal pattern.

Here's one way to do it:

restart:
macro(DT= DocumentTools):
DT:-Do(%TextArea2 = eval(DT:-Do(%MathContainer0), [x= %TextArea0, y= %TextArea1])):

I am not very familiar with DocumentTools, and I suspect that there are numerous simpler ways to do this.

Of course there is no algorithm for that. That's light-years beyond the capability of any human or computer mathematician.

You should use the parameters. One reason is that if there's a bug in your code that's caused by misspelling a parameter, it can be easily found with maplemint. Why quibble about typing a hundred words, which is like a medium-length paragraph on MaplePrimes? This one has about fifty.

If I were writing the code, I'd put a comment, just a few words, after each parameter. The code will behave better if you respect it rather than mistreat it. Respect your code!

Every example statement that you wrote is correct except for this one:

option if x1 = .. else... end; 

option is not supposed to be followed by a statement. It is supposed to be followed by a keyword. You can find the keywords that have predefined meanings at ?option. You can also use your own keywords, which you can give meanings, or simply use for documentation. For example, I often do

option `Author: Carl Love <carl.j.love@gmail.com> 7-Dec-2018`;

The difference between doing this and using a comment is that the options are integral and easily accessible parts of the "compiled" code.

You asked about module() end module. While this construction is syntactically valid, and it does return a valid module, I can't immediately think of a practical use for it. But things 0{}, [], [][], (), and NULL are all quite useful, so I suspect that the empty module can be useful also.

You want to iterate an operation over a container of operands. There are many ways to do it. Two ways are

Rank~([G1]);

or

map(Rank, [G1]);

Your original command returned G1 as a sequence of matrices. Putting G1 in square brackets, [G1], makes it a list. Sequences are the most unwieldy of containers, and they can't be used for most forms of argument passing.

In addition to what VV said, try using 

LinearAlgebra:-LinearSolve(m2, b, method= SparseDirect).

If your equations are redundant, then there's nothing incorrect about the appearence of one of the "solved for" variables on the right side of a solution equation.

You'll need to upload a complete code for a deeper analysis of the situation.

You need to make assumptions on the parameters, and it doesn't seem so simple to me. Consider the 2D case:

int(a*b/sqrt((x-a)^2+(y-b)^2, [a= -1..1, b= -1..1])) assuming x > 2, y > 2;

That's a fairly complicated answer, although still an elementary function. Extending that to the 3D case, my Maple 2018 has been working on it for 40 minutes. No answer yet, but I think that one is coming.

In the somewhat confusing terminology of combinatorics, a partition (of an integer, not a set) is just a composition without regard to order. So, the following works:

select(p-> nops(p)=3, combinat:-partition(7));

Furthermore, it is obvious that the maximum possible entry in any such partition is 5 = 7-3+1, so the above command could be made more efficient as

select(p-> nops(p)=3, combinat:-partition(7,5));

Inside your loop, you have the statement

p:= solve(egp, p);

The first time through the loop, it works. But after this statement is executed once, p is assigned a value, and hence it's no longer a symbolic variable. So an error occurs the second time the solve is executed.

To correct the problem. make the first statement inside the loop (after all the for lines):

p:= 'p';

That's how you remove any assigned value that a variable has. (And this statement safely does nothing the first time through the loop, when p doesn't have a value anyway.)

There may be some other problems with your code (the output looks weird), but the above issue is definitely the major issue.

Note that your loops as they're currently bounded will produce close to 100 million iterations (92,692,600 to be exact). Do you really want to print output for every iteration? 

If is a set of sets, then the following all produce identical results:

  1. `union`(S[]) (works for S::{list,set}(set))
  2. op~(S) (works for S::set({list, set}))
  3. {seq(s[], s= S)} (works for S::{list,set}(list,set))

All are quite fast, but I've often wondered which is fastest. I haven't been able prove it definitely. I've convinced myself that 3 is faster than 2, which is a disappointment since 3 uses annoying, stupid syntax. But I haven't been able to rank 1 in relation to 3. What these operations do is not entirely trivial, because Maple sets have duplicates removed and are stored sorted into a canonical order.

If the members of S are not themselves sets, then there's no replacement for `union`. For example, you can express the union of pure symbols: `union`(A,B,C).

I am curious what process leads to Maple returning an ODE solution of that form. But, taking your word for it, suppose that you have an expression (possibly an equation, as above, or any other expression) e and you want to extract from it all function names that begin with Z and are followed by an integer. Then do

map2(op, 0, indets(e, typefunc(suffixed('Z', integer))));

If the names actually begin with _Z, then simply change 'Z' to '_Z'.

First 154 155 156 157 158 159 160 Last Page 156 of 395