Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are replies submitted by Joe Riel

You can use the alias command so that the dependence on t is hidden, which makes both the entry and the display a bit nicer:
alias(theta=theta(t),x=x(t)):
simplify(diff(tan(theta)=1/x,t)):
convert(%,sec);
               diff(theta,t)*sec(theta)^2 = -1/x^2*diff(x,t)
Another approach is to use the unit_free conversion. However, because it doesn't work directly on rtables, for your example you'd have to do
map(convert, M, unit_free)
which isn't quite as nice as Alec's suggestion. Note that convert/unit_free takes an optional third argument that is assigned the stripped unit. In my opinion there should be a link to the convert/unit_free help page (see ?convert/unit_free) on the main Units help page [that usually means there is, but I cannot see it 8-].
Alec's useful suggestion works because lexorder[0] does not match the symbols known to sort (viz., lexorder, lexorder[1], lexorder[2], etc.) and so is interpreted by sort as a procedure name. The builtin procedure lexorder (see ?lexorder) is then called. The 0 is ignored. The same thing happens if NULL or any non posint expression is used. Unlike the procedure called when the symbol exorder is passed to sort, the separate lexorder procedure can handle indexed names. I've added a sixth procedure to my tests:
SortNames[6] := proc(names :: list)
    sort(names, lexorder[]);
end proc:
Here is the updated table output (new columns are because I've rewritten the code that does the timing):
Compare performance of sorting names.
Each test sorts the same list of 500 names of 5 characters 20 times.

----- timing -------  ---------- memory ------------
total (s)  maple (s)  used (MB)  alloc (MB)  gctimes  proc
---------  ---------  ---------  ----------  -------  ----
  2.34       1.54     36.11       34.18         0     SortNames[1]
  2.54       2.50     31.20       29.24         0     SortNames[2]
  0.16       0.16      2.00        1.87         0     SortNames[3]
  0.19       0.19      2.57        2.44         0     SortNames[4]
  0.23       0.23      4.46        4.00         0     SortNames[5]
  0.14       0.11      5.73        5.69         0     SortNames[6]
Previously I had recommended using SortNames[4]. This method is faster but uses more memory. However, given its simplicity I recommend it.
Note that you can pass the independent variable, x, as an optional argument to map:
map(diff, M, x)
Your comments are mainly correct, though I don't understand why the first routine centers the output. What version and interface of Maple are you using? It prints flush left for me (Maple 10, standard and cmaple), on linux. The output of debugopts with the procdump option is a name (not a string, as you note). I don't know why that is; probably a vestige of early Maple. Strings weren't introduced until Maple R5. I'm not sure why the backslashes are doubled in the line that you show; they shouldn't be.
If you need to do this a lot, that is, display an output in 1D, but prefer to use the 2D setting for normal viewing, you might assign a macro to make this a bit easier to type. Thus
# assign macro named ~ that lprints the previous expression
> macro(~ = lprint(%)):
> (x+1)^2;                  
                       2
                (x + 1)

> ~;                        
(x+1)^2
If you need to do this a lot, that is, display an output in 1D, but prefer to use the 2D setting for normal viewing, you might assign a macro to make this a bit easier to type. Thus
# assign macro named ~ that lprints the previous expression
> macro(~ = lprint(%)):
> (x+1)^2;                  
                       2
                (x + 1)

> ~;                        
(x+1)^2
The way we should be able to do this (set indentation) is to modify the routine to set the interface('indentamount') value to that desired. Use a local variable to save and restore the previous value, if desired. Unfortunately, the print driver in the standard GUI ignores the indentamount setting (as it does the screenwidth). It works fine in cmaple or the classic GUI. Here is one way to work around that. It uses the output of showstat to convert a procedure to a string, removes the line numbers, then doubles the number of blank space at the start of each line. Because showshat uses a nominal indent of two spaces per level, that effectively gives an indent of four spaces per level. PS: After posting this, I reread your question. I originally thought you wanted an indent of 4 spaces per level, not 2. You shouldn't have to do anything to my original version of PrintProc to get an indent of 2 spaces per level.
PrintProc := proc(p)
local width,opaque,dummy_name,lead,lines,str;
option `Copyright (C) 2004 by Joseph S. Riel. All rights reserved.`;
description "Print like showstat, but without line numbers";
uses StringTools;
    if not p::procedure then
        lprint(eval(p));
        return NULL;
    end if;
    opaque := kernelopts('opaquemodules'=false);
    width := interface('screenwidth'=80);

    try
        str := RegSubs("\n ...." = "\n"
                       , debugopts('procdump'= p));
        str := RegSubs("\n( +)" = "\n\\1\\1", str);
        printf("%s:\n", str[1..-2]);
    catch "procedure name expected":
        error "%1 is not a procedure name",p;
    catch "cannot debug the debugger":
        dummy_name := eval(p);
        procname(dummy_name,args[2..-1]);
    catch "cannot debug built-in functions":
        printf("%A := %A\n", p, eval(p));
    finally
        interface('screenwidth' = width);
        kernelopts('opaquemodules' = opaque);
    end try;
    NULL;
end proc:
Note that showstat doesn't display options, so you won't ever see the
option `Copyright (c) ...`;
statement with this routine.
Here is another approach. Instead of using eval to print the body of a procedure, use the following procedure, which sets interface(prettyprint=1) so that the output is in a fixed-width font. The display is not quite as nice as the usual Maple outut (in a GUI), the line breaking is not quite as good, but it is acceptable for most usage and makes cutting/pasting the result into an input section simple and, because the indentation is done via spaces, is readily edited. You might consider assigning this procedure in your Maple initialization file.
PrintProc := proc(p)
local opaque,pretty,verbose,width;
    (pretty, verbose, width) := interface('prettyprint' = 1
                                          , 'verboseproc' = 2
                                          , 'screenwidth' = 120
                                         );
    opaque := kernelopts('opaquemodules' = false);
    try
        print(eval(p));
    finally
        interface('prettyprint' = pretty
                  , 'verboseproc' = verbose
                  , 'screenwidth' = width );
        kernelopts('opaquemodules' = opaque);
    end try;
    NULL;
end proc:
Maple 10's solve can handle a list (square brackets) of equations. Earlier versions required sets (curly braces). Use convert( a_list, set) to convert to a set.
Maple 10's solve can handle a list (square brackets) of equations. Earlier versions required sets (curly braces). Use convert( a_list, set) to convert to a set.
The poster is interested in b^u * b^v, not x^p * y^p. Consider (-1)^1 = (-1)^(1/2 + 1/2) = (-1)^(1/2) * (-1)^(1/2). If different roots of -1 are used (i and -i), we get 1 rather than -1.
The poster is interested in b^u * b^v, not x^p * y^p. Consider (-1)^1 = (-1)^(1/2 + 1/2) = (-1)^(1/2) * (-1)^(1/2). If different roots of -1 are used (i and -i), we get 1 rather than -1.
For now I'll just answer the easy one. The assignment
r := 'r':
is simply clearing any previous assignment to the r variable. In the context of VectorCalculus this would be necessary if r was one of the coordinates in a coordinate system. That is, if you had previousl done, say,
r := 1:
then attempting
SetCoordinates(spherical[r,phi,theta]);
would fail. Clearing the r variable (as well as phi and theta) allows it to work.
For now I'll just answer the easy one. The assignment
r := 'r':
is simply clearing any previous assignment to the r variable. In the context of VectorCalculus this would be necessary if r was one of the coordinates in a coordinate system. That is, if you had previousl done, say,
r := 1:
then attempting
SetCoordinates(spherical[r,phi,theta]);
would fail. Clearing the r variable (as well as phi and theta) allows it to work.
First 180 181 182 183 184 185 186 Last Page 182 of 195