acer

32747 Reputation

29 Badges

20 years, 112 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Loading the Units:-Standard package will rebind several commands (`+`, `*`, etc) so that they automatically simplify units when called from the top-level.

However you can still get unsimplified arithmetic expressions containing units as results from other commands, So units simplification is something you may have to do yourself, at some stage, anyway.

There is a right-click context-menu action for it.

There are also several ways to get it, with commands (some of which are not in the Units subpackage).


K := Unit('m')+Unit('mm')

Units:-Unit('m')+Units:-Unit('mm')

simplify(K)

(1001/1000)*Units:-Unit('m')

Units:-Standard:-simplify(K);

(1001/1000)*Units:-Unit('m')

combine(K, 'units')

(1001/1000)*Units:-Unit('m')


Download unitsimp.mw

acer

If you issue the Maple command

libname;

then what does it show? It should reveal one or more folders (locations) that Maple is using for so-called Library archives and help-databases. Tech Support is suggesting that you place the files in one of those (...the same one as holds the principle maple.mla archive).

There are two other ways to get it all to work. One is to place them all in a new subfolder like whatever this command returns,

cat(kernelopts(':-homedir'),"/maple/toolbox/directsearch/lib");

A third way is to place the three files in any new special folder of your choice, and then to augment your default for libname in Maple by augmenting libname with a command in a Maple initialization file. That works, but the location of the initialization file varies by platform.

For all three ways above, close Maple's GUI entirely, and relaunch when the steps are completed.

I prefer the second choice above, as it's a single solution that can make it work in one or more (or future) Maple versions you might have, and doesn't mess with your Maple installation. The first suggestion is also in the readme of the DirectSearch v2 download. The 3rd method above corrects an alternate, flawed suggestion in the DirectSearch v2 readme, so that it makes the Help-pages work as well as the commands.

 

acer

See Quantile.

with(Student:-Statistics):

X:=NormalRandomVariable(0,1):

p:=Probability(X<=0.6);
                           p := 0.725746882249926

Quantile(X,p);
                              0.600000000000047

acer

You can of course experiment with a procedure like F which computes the placement according to the adjacent points. For example you could even estimate the concavity so as to try and place the textplots on the "outside".

restart;
tp:=[0., 0.8e-1, .16, .24, .32, .4, .48, .56, .64, .72, .8,
     .88, .96, 1.04, 1.12, 1.2, 1.28, 1.36, 1.44, 1.52, 1.6,
     1.68, 1.76, 1.84, 1.92, 2.0]:
theta4:=[.7908689661, .3741753003, 1.649095014, 2.518788513,
         .7373585234, .4970414167, .5684031862, .4888977241,
         1.142477381, 1.810790643, .7854189206, .4992350790,
        .4145062614, .5655254887, .7238064921, .9972543194,
        .3994980275, -2.779042530, .6444066751, .9318149247,
        .8593318817, .2546628449, 3.096169222, 1.562607652,
        .5534976436, 1.097828390]:
with(plots):

F:=proc(n)
     option remember,system;
     if n=1 then "left";
     elif n=nops(tp) then "right";
     elif theta4[n-1]>=theta4[n] then
        if theta4[n+1]>=theta4[n] then "below";
        else "below","left";
        end if;
     elif theta4[n-1]<=theta4[n] then
        if theta4[n+1]<=theta4[n] then "above";
        else "above","left";
        end if;
     else NULL;
     end if;
   end proc:

hscal:=abs(max(theta4)-min(theta4)):
S:=proc(i)
  local f;
  f:={F(i)};
  if f={"above"} then 0.01*hscal;
  elif f={"below"} then -0.01*hscal;
  else 0.0; end if;
end proc:

display(pointplot(tp,theta4,style=line,color=red),
        pointplot(tp,theta4,style=point,symbolsize=6,color=red),
        seq(textplot([tp[i],S(i)+theta4[i],tp[i],
                      font=["helvetica",bold,10]],
                     color="Orange",align={F(i)}),i=1..nops(tp)),
        gridlines=false,size=[600,400]);

tag2.mw

acer

@Ronan Matrices (or Vectors or Arrays) behave differently than usual under `eval`, so that their entries are not undesirably evaluated when the Matrix is passed as the argument to a procedure.

The focus is instead shifted (somewhat) to evaluation upon element access.

There are a few ways to get a copy of the Matrix whose entries contain names which (due to later assignment) evaluate to something different later on (such as your `a`, later assigned to 5, in the order or operations that Carl suggested).

But you shouldn't need to reach for such a hammer as `simplify`, just to get the evaluation effect.


# First, let's see what went on with the original approach.
restart;

a:=5;

5

M:=Matrix([[a,2*a],[3*a,a^2]]);

M := Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25})

M;

Matrix([[5, 10], [15, 25]])

# There is no instance of `a` within M, which is why unassignment to `a` does not affect M.
lprint(M);

Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

# Now let's see what happens with the reverse approach.
restart;

M:=Matrix([[a,2*a],[3*a,a^2]]);

M := Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25})

a:=5;

5

# You see the 5, not 'a', but this is just an artefact of evaluation during printing.
M;

Matrix([[5, 10], [15, 25]])

# Entries are evaluated upon access. Together with the printing, as above, this is often adequate.
M[2,2];

25

lprint(M); # Indeed the 'a' is still there.

Matrix(2, 2, {(1, 1) = a, (1, 2) = 2*a, (2, 1) = 3*a, (2, 2) = a^2}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

C:=copy(M);

C := Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25})

# This copy of M contains the 5, not the 'a', as entries were evaluated upon access during copying.
lprint(C);

Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

# This new version of M also contains 5, not 'a'.
K:=rtable_eval(M);

K := Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25})

# And here is proof of that.
lprint(K);

Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

# M still contains 'a', though elementwise access will get the 5.
lprint(M);

Matrix(2, 2, {(1, 1) = a, (1, 2) = 2*a, (2, 1) = 3*a, (2, 2) = a^2}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

# This causes the entries of M to be evaluated in-situ, without copying the whole structure.
rtable_eval(M, inplace);

Matrix([[5, 10], [15, 25]])

lprint(M);

Matrix(2, 2, {(1, 1) = 5, (1, 2) = 10, (2, 1) = 15, (2, 2) = 25}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

 


Download rtable_eval.mw

 

Use add for adding up a finite number of items, not sum.

L(1):=[1,2,3]:         
L(2):=[A,B,C]:         

add(nops(L(i)),i=1..2);
                                                             6

If you insist on using sum for this then notice that it does not have special evaluations rules. The first argument is evaluated before it adds things up.

sum('nops'(L(i)),i=1..2); 
                                                             6

You original mistaken use was just adding this value twice.

nops(L(i));
                                                             1

acer

RootFinding:-Isolate may be considered as a lower-level tool. It is also in use by fsolve for the univariate case.

acer

It is ctrl-r .

See the help, for more.

acer

A := [ [2,3], [4,5] ,[6,7]]:

map( `/`@op, A );
                                  [2  4  6]
                                  [-, -, -]
                                  [3  5  7]

In current Maple this can be shortened to,

(`/`@op)~(A);

acer

Just change the verticalasymptoteoptions option to be,

'verticalasymptoteoptions' = ['color' = "Black", 'linestyle' = 'spacedash']

acer

For floating-point Matrices the LinearAlgebra:-Eigenvectors command computes the eigenvectors using something like the qr/qz algorithm implemented in compiled external libraries.

For symbolic Matrices the LinearAlgebra:-Eigenvectors command calls LinearAlgebra:-NullSpace on the characteristic matrix for lambda as each of the computed eigenvalues. Note that in this case the initial solving for the eigenvalues explicitly can itself be difficult since the characteristic polynomial (in unknown lambda) may be difficult or impossible to fully factor.

And the coefficient domain can also throw a wrench in the works, in the symbolic case. For example the special case of Matrices with entries being algebaric expressions with floating-point coefficients may be problematic. It's not difficult to come up with such a Matrix, for which manual eigenvector computation (via NullSpace of the the Characteristic Matrix instantiated at each computed explicit eigenvalue) is achievable even though LinearAlgebra:-Eigenvectors baulks... (should it refuse to attempt a problem from a class for which it may miscompute?).

acer

Use the capitalized command name Matrix to create your d and Phi for use with the LinearAlgebra[Generic] package, not matrix.

acer

To answer your questions:

1) The evalf command uses remember tables to store computed results, so that it can quickly look them up instead of recomputing if given the same input at the same (or lower) Digits. But, in order to keep the amount of stored results manageable, the stored results may be cleared when a garbage collection is done.

This is similar to the behaviour you can get on your own procedures, when re-passing previous inputs, if your procedure has option remember,system . Well, the remember table behaviour can be similar, though the interplay with Digits is a special finesse that evalf gets from the kernel.

So the second time your example runs some results may be remembered and thus appear to be computed more quickly (because they are not all being recomputed!). But there is also the possibility that a garbage collection will occur, wiping out that benefit (and in older Maple versions causing a separate delay while it collects).

2) These floating point computations are done by default using software representations of floating point numbers. This is what allows Maple to do floating-point computations at high precision. There are several ways to make Maple use hardware double-precision floating-point numbers for this instead. See here for a brief read.

One of the key things worth noting in Axel's good Answer is that it can also be significantly better to run a whole procedure under a single call to evalhf than to make repeated calls to evalhf inside a loop.

acer

You cannot use Tabulate and Explore in the same paragraph or execution group as in that case they both write to the same Task region. The same goes for ImageTools:-Embed or anything else that uses DocumentTools:-InsertContent. 

This is a known limitation, documented to some extent in Maple 2016.

The above relates to making separate calls to Explore and Tabulate in the same execution group. Your particular example of a nested csll also cannot work (as is, at present) because Tabulate returns NULL and merely displays results. Tabulate is not returning a result which can be passed to Explore programmatically.

I give your question an up-vote because I like the implications that 1) Explore should be able to handle a grid of "explorations" (which might not all need to be plots), and 2) there should finer control over how plots:-display(Array(...)) or _ARRAYPLOT render, and with in Table Cells should at very least be sensibly aligned and respect PLOT sizes.

As things stand right now you can Explore a plots:-display(Array(...)) call, as you've suggested. But handling of sized plots doesn't work so well in that, and individual cell coloring is not supported, and cell alignment is wonky. Also, all cells get updated upon changed value of any exploration parameter. It would be more useful if the Explore command syntax allowed one to specify a grid (listlist?) of items to explore, including any of plots/expressions/images, each updatable only when only its own dependent parameters changed, and fully supporting individual cell alignment/shading.

acer

If your expression is assigned to name expr then try the command combine(expr, power) .

You might also take a look at simplify(expr, power) which does some additonal work (eg, grouping).

The commands combine(expr) and simplify(expr) will also work, for your particular example. But they can do more work in general, changing some other example in an additional way that might not be desired. The command combine(expr, power) might help get just the change you've described.

acer

First 213 214 215 216 217 218 219 Last Page 215 of 341