acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

One of the calls to writeto is inside GTS2Usage and the other is at the top-level.

So you are redirecting to MyFile, and then not reverting to terminal (unless you successfully call GTS2Usage, which I don't see anywhere in the sheet). That's probably why you're not seeing the later output in the sheet.

Perhaps you intended something like the following, instead. Note that the finally clause is there so that, regardless of whether an error occurs, the writeto(terminal) will execute.

GTS2Usage := proc(H, F, Na, Nd)
  try
    MyFile := "C:/Users/Moshe/Desktop/Usage";
    writeto(MyFile)
    CodeTools:-Usage(GTS2(H, F, Na, Nd));
  catch:
    error;
  finally
    writeto(terminal);
  end try;
end proc;

The try..catch can trap most errors, but not infinite recursion (just so you are aware).

Also, even though you haven't yet shown how you plan to use GTS2timer yet, that proc looks suspect. It only returns the time() difference, and the results from GTS2 would be discarded. And GTS2 returns its results and doesn't act in-place on anything. Perhaps you intended it more like this:

GTS2timer := proc(H, F, Na, Nd)
  local res, st;
  st := time();
  res := GTS2(H, F, Na, Nd);
  print( out = time()-st );
  return res;
end proc;

Do you really need individual timings for each GTS2 call? Are you trying to figure out why it sometimes consumes much resources for specific inputs, or are you also interested in how its internals are consuming resources for general inputs? I'm just wondering whether profiling GTS2 might also be of interest to you.

Note that the value of your Fcn1 is not sqrt(a), because the call to sqrt has evaluated.

Fcn1 := sqrt(a):

lprint(Fcn1);
  a^(1/2)

You can delay evaluation when assigning to Fcn1, and then pass to codegen[cost] with only 1-level evaluation of its argument.

restart;              
Fcn1 := 'sqrt(a)';

                  Fcn1 := sqrt(a)

codegen[cost]( eval(Fcn1, 1) );

                     functions

Fcn2 := 'sin(sqrt(a))';

                Fcn2 := sin(sqrt(a))

codegen[cost]( eval(Fcn2, 1) );

                    2 functions

But this approach may not help much if the expressions your trying to measure are the result of some computation. Another approach might be be to have your computations done by procedure(s), and then measure their cost(s). Eg,

restart;
f := proc() sin(sqrt(a)); end proc;

        f := proc() sin(sqrt(a)) end proc

codegen[cost]( f );
                  2 functions

It's difficult to suggest an approach without knowing more about where your target expressions come from. Are they the result of a separate computation? Or is it their computation/production that you are trying to measure?

As a side note (possibly not relevant to you), even using a procedure will not prevent automatic simplification, since that also occurs during the interal re-writing of the statement sequences in the procedure body. (A more modern implementation might make use of ToInert, but that's another story.) For example,

restart;

'2*(x+y)';  # automatic simplification cannot be prevented by uneval quotes

                      2 x + 2 y

codegen[cost]( '2*(x+y)' );

            additions + 2 multiplications

codegen[cost]( proc() 2*(x+y); end proc );

            additions + 2 multiplications

# internally, this happened
`intrep/makeintrep`( proc() 2*(x+y); end proc );

     Proc(Name(nam .. float), Parameters(), Options(),
          Description(), Locals(), Globals(),
          StatSeq(2 x + 2 y))

Here are two ways to create it.

You could create either row Vectors or column Vectors, depending on which you want.

Vector[row]([seq(0..20,0.5)]);

# trunc((20-0)/(0.5)+1)  is just 41

Vector[row]( trunc((20-0)/(0.5)+1) ,(i)->(i-1)*0.5);

Apart from suppressing the ellipses altogether (as Thu has shown), there is also the possibility of stretching the ellipse or reducing the font size.

Your question mentioned the possibility to "modify the ellipses", but without "ad hoc modifications". Surely that only makes sense if you provide at least some guideline of what would be an acceptable modification. For example, do you mean that you would only want the ellipse re-jigged to the longest label if it could be done fully automatically and robustly?

I'll toss these out there, in case another reader is interested but with less restrictions about ad hoc changes.

restart;
with(GraphTheory):
g := Graph({{"azertyuiopqsdfghjklmwxcvbn", 1}, {"azertyuiopqsdfghjklmwxcvbn", 2}}):
P := DrawGraph(g, style=tree, root="azertyuiopqsdfghjklmwxcvbn"):
P;
subsindets(P,specfunc(FONT),u->FONT("HELVETICA","DEFAULT",8));
plots:-display(P,size=[1000,1/2]);

Matrix indexing starts from 1.  But Array indexing can start from 0 (or whatever you want).

And you can create an rtable-Alias of a Matrix that behaves like an Array and which starts its indexing from 0.

Since it is an Alias, changes to either of them also appear in the other. They act like views onto the same data in memory.

So you can use indexing-from-zero to assign to (or access from) the Array's name, but the values will come from the Matrix. And vice-versa.

restart;

X := LinearAlgebra:-RandomMatrix(3);

Matrix(3, 3, {(1, 1) = 27, (1, 2) = 99, (1, 3) = 92, (2, 1) = 8, (2, 2) = 29, (2, 3) = -31, (3, 1) = 69, (3, 2) = 44, (3, 3) = 67})

(1)

XA := ArrayTools:-Alias(X, [0..2,0..2]):

X[1,1];

27

(2)

XA[0,0];

27

(3)

XA[0,0] := 17;

17

(4)

X[1,1];

17

(5)

X . X;  # usual Matrix-Matrix multiplication

Matrix(3, 3, {(1, 1) = 7429, (1, 2) = 8602, (1, 3) = 4659, (2, 1) = -1771, (2, 2) = 269, (2, 3) = -2240, (3, 1) = 6148, (3, 2) = 11055, (3, 3) = 9473})

(6)

XA . XA:  # elementwise multiplication
Matrix(%);

Matrix(3, 3, {(1, 1) = 289, (1, 2) = 9801, (1, 3) = 8464, (2, 1) = 64, (2, 2) = 841, (2, 3) = 961, (3, 1) = 4761, (3, 2) = 1936, (3, 3) = 4489})

(7)

 

Download MatrixArrayAlias.mw

 

Did you try,

interface(prettyprint=1):

in your cmaple session?

That is the default for the Command Line Interface (CLI).

Executing the code which defines a procedure is not the same as calling that procedure.

You have done the former, but not the latter.

More specifically, applying eval to a procedure does not call the procedure.

To actually call the procedure use round brackets. That applies it (even if there are no arguments within the brackets).

So, if

Glyph2:-GetSpace('default')

returned a procedure then the following would also immediately call that returned procedure (ie. apply it to zero arguments, or invoke it).

Glyph2:-GetSpace('default')()

In your actual module example I don't see the point of wrapping some procedure definitions in uneval quotes (single right quotes).

You can accomplish that by putting a call to plots:-setoptions in a custom initialization file.

E.g.,

plots:-setoptions( 'font'=[ "Tahoma", 24 ] ):

See the Help page for topic plot,options for more details on the choices. The single item font covers several related suboptions (ie. font alone covers axesfont, captionfont, labelfont, and titlefont) .

The setoptions command sets values that act like defaults (for the duration of the session). But these can still, in turn, be overridden by options supplied directly in subsequent calls to individual plotting commands.

In Maple 2016.2 entering   3!!   in 2D Input mode produces a popup dialogues that queries which one you intend.

In Maple 2018.1 that popup dialogue doesn't appear, and that 2D Input gets parsed as (3!)! .

The appearance of that disambiguation popup dialogue does not appear to be tied to the value of interface(typesetting) .

AFAIK there isn't a way to force it and avoid the popup in Maple 2016 by using Typesetting:-Settings().

 

Firstly, you have a history of supplying only toy examples, and then when people offer a solution you point out that it works for the toy examples but not your as-yet-undisclosed actual problem.

So please show your full problem(s) up front.

With the meagre details you've supplied it isn't clear why you can't just substitute y=u*x and proceed from there. Do you only want *some* instances of y to be treated, and if so what is the precise delineation of when you want that?

restart;
expr1  := sqrt(x*y)/x:
simplify( subs(y=u*x, expr1), symbolic );

                     1/2
                    u

restart;                                 
expr1 := sqrt(x^2+y^2)/x:
simplify( subs(y=u*x, expr1), symbolic );

                   2     1/2
                 (u  + 1)

Secondly, why are you so keen on using the symbolic option of simplify and combine when doing so can give you results that are not correct in general?

I'm guessing that you are asking about the height and width of the plot as rendered on the Worksheet/Document canvas, and not about the ranges that are shown on the horizontal and vertical axes.

There is no way in Maple 13 to programmatically and directly set the width and height of the rendered box in which a plot is displayed as output.

You can, of course, resize the plot by manually adjusting the border with the mouse pointer.

If you really want to be able to insert a rendered plot with specific height and width values (eg, 900x900 pixels) in a Worksheet/Document in the Standard GUI of Maple 13, then you might have a look at this old Post.

Another programmatic methodology consists of using a script -- which could be Maple, via its XMLTools package -- and modifying the height/width fields of the inline-plot items in a saved (XML) .mw file. I recall Preben or someone once saying they'd done that. This requires closing/saving and re-opening the sheet, and so it is not a direct modification of the appearance of plot output. This is quite advanced a technique.

In recent Maple versions up to Maple 2018, there is a size option on the 2D plot command which allows you to specify the height and width easily.

If you are asking about examining or extracting the data structure that holds the computed details of the plot and its features then the commands plottools:-getdata and op can work.

I don't generally recommend using the lprint command for such examination since for many plots that would produce a less legible output.

If instead you are asking about how to get at the original plotting command that produced a given plot, then no that is not stored as part of the plot itself.

See the help page for the command IterativeMaps:-Bifurcation .

 

(Some readers might also find some interesting bits in this old discussion. The first paragraph in my first Comment there contains links to another three earlier threads.)

 

This is quite similar in nature to your previous question.

a := 3;
                      a := 3

f := unapply(a*x, x);

                    f := x -> 3 x

g := subs(dummy=a, x->dummy*x);    

                    g := x -> 3 x

The command unapply handles your example, whether you want the name of the formal parameter to be x or X.

x^2;

                    2
                   x

f := unapply(%, x);

                           2
                f := x -> x

f(t);

                     2
                    t

x^2;
                     2
                    x

f := unapply(subs(x=X,%), X);

                            2
                 f := X -> X

f(t);

                      2
                     t

You *could* construct an operator/procedure that actually uses eval to evaluate the given expression (in x) at x=X where X is the name of the formal parameter. But it would be inefficient to have it do so upon every application of f, and for your example it would be unnecessarily inefficient.

x^2;

                      2
                     x

f := unapply('eval'(%,x=X),X);

                          2|
               f := X -> x |
                           |x = X

lprint(eval(f));
  X -> eval(x^2,x = X)

f(t);

                      2
                     t
First 175 176 177 178 179 180 181 Last Page 177 of 336