Joe Riel

7722 Reputation

22 Badges

14 years, 138 days

MaplePrimes Activity


These are replies submitted by Joe Riel

You could use two prismatic joints to enforce a planar motion.  The planar joint could also be used.  A different approach would be to use the sphere-rectangle contact, though that would allow motion off the surface (bouncing).

@a_simsim It helps to know why two backslashes are required, in a Maple string, to represent a Windows directory separator. The backslash is used as an escape character, to permit entering special characters (new-lines, tabs, arbitrary ascii). As such, to enter the escape character itself, you need two of them, the first "escapes" the second.

Have someone do it for you. Snarky answer aside, what are you trying to make efficient?  The execution of the procedure, or the creation of the procedure? The usual concern is the former. 

@Ramakrishnan On line 95 there is a call to SetProperty that is missing its package name (should be DT:-SetProperty); without the package name it returns unevaluated.

In the embedded component code sections, the "use DocumentTools in ... end use;" wrappers are no longer needed as there are no exports of DocumentTools being used in the code.  It probably isn't worthwhile to remove the wrappers, but it is something to consider for the next worksheet.

 

@Carl Love Nice extension, particulary the use of an operator for a positional argument. Hmm. Is there a type 'operator'? There should be.  Probably there should be a check for the number of dimensions of an rtable; it seems unlikely anyone would want to sort a 2 or higher dimensioned rtable by the linear order.

@Kitonum The OP should be aware that this method is horrendously inefficient.  The issue is that every swap generates an entirely new list.  Such manipulations should be done on a mutable structure; here an Array or Vector would be appropriate. The changes to the code are easy:

BubbleSort := proc(L::list(numeric))
local A, n, k, m;
    A := Array(L);
    n := upperbound(A,1);
    for k from 0 to n-2 do
        for m from 1 to n-k-1 do
            if A[m] > A[m+1] then
                # swap elements at indices m, m+1
                (A[m],A[m+1]) := (A[m+1],A[m]);
            end if;
        od;
    od;
    convert(A, list);
end proc:

To expand on acer's response, there are two usages of the uses keyword:  uses DocumentTools and uses DT=DocumentTools.  The former makes all the exports of DocumentTools available in the procedure (or module).  The latter provides a shorthand that expands subsequent uses of DT to DocumentTools.  While the former may be more convenient, if you unintentionally use an export of DocumentTools the result may not be what you expect. Further, if at a later date new exports are added to DocumentTools, there may be a conflict with your code. Unless it is throwaway code, I invariably use the second form; I find it safer and clearer.  A minor downside with using the second form is that mint (Maple's syntax checker) will throw occasional nags about the shortname being undeclared.

Curiously, the issue doesn't seem to be due to the attempted creation of the MutableSet, but rather the evaluation of the expression in the seq.  That is

CodeTools:-Usage(seq(CodeTools:-Usage([seq(C[i+1],i=1..N-1)]):
memory used=212.87MiB, alloc change=0 bytes, cpu time=6.32s, real time=5.56s, gc time=1.36s

But the following doesn't finish in a reasonable time:

CodeTools:-Usage(seq(CodeTools:-Usage([seq(C[i+1]-C[i],i=1..N-1)]):

Will submit this as a bug.

.

@tomleslie I'm not seeing the basis for the simple expression.  Consider the case when n=2.  The correct answer is clearly 2, but the expression gives 3. Regardless, the answer for the OP's question has to be an integer.

@Rim It would be useful to post these equations in an accessible manner; retyping from a picture is error prone and tedious.  Does Simplify mean something different than simplify?

 

@vv Better would be n -> mods(n+1,3), or the inert expression %mods(n+1,3).

@Kitonum Expanding on that,

(**) y1 := rsolve({b(n)+b(n-1)+b(n-2)=0, b(0)=1, b(1)=-1, b(2)=0}, b(n)):
(**) y2 := evalc(y1);
                                                         2 n Pi         1/2     2 n Pi
                                               y2 := cos(------) - 1/3 3    sin(------)
                                                           3                      3

(**) y3 := expand(subs(n = 3*j+k, y2)):
(**) y4 := simplify(y3) assuming j :: integer;
                                                           1/2     2 Pi k        2 Pi k
                                               y4 := -1/3 3    sin(------) + cos(------)
                                                                     3             3
(**) seq(eval(y4, k=kk), kk=0..2);
                                                               1, -1, 0

On the other hand, I think it is more convincing to solve for b(n) as b(n) = -b(n-1) - b(n-2) and then compute the results manually.

@Rim Hard to say without seeing the expressions---and if they are really large or unwieldy it might still be hard to say. What happens if you eliminate the call to simplify?  Sometimes what you really want is a simpler transformation, say collect terms.

@Rim I'll guess that whatever you are passing to simplify is a large expression, so repeated calls will take a lot of time.  Generally I try to avoid calling simplify in an algorithm and instead use a more specific procedure.  Is there a particular type of simplification you are trying to achieve at that point?

@Rim Interesting. The 32 indicates that line was executed 32 times.  The 56393,345 is the total number of seconds required; that is approximately 16 hours, does that seem right?  I'm assuming your locale is using the comma for the radix. The negative sign for the words usage suggests that the 8 byte word (I'm guessing) used to store the value has exceeded its range, or possibly the printing mechanism doesn't know that it is supposed to print it as an unsigned integer. 

Does that line call a procedure?  If so, then the usual thing to do is to profile it.  If you do so, and also profile this procedure (you can profile more than one, just use a separate call to debugopts('traceproc' = some_func), the reported time in the line of the calling procedure will be apparently greatly reduced because of the way Maple's profiler reports the time (i.e. it doesn't show cumulatives at the calling procedure if the called procedure is profiled).

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