acer

32647 Reputation

29 Badges

20 years, 57 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Replace pi with Pi.

In Maple, lowercase pi doesn't mean anything special.

acer

Your integration range is being supplied as f=100..1000 where the range endpoints 100 and 1000 are exact integer (not floating-point) values. In that case, calling value() will bring about exact integration rather than numerical quadrature.

To get (here, much faster) numerical quadrature call evalf() instead of value(), or replace 100..1000 with 100.0..1000.0 as a floating-point range.

See the ?evalf,Int help-page.

acer

This has the advantage that it doesn't involve having to repeat actions with the mouse pointer (ie. is programmatic). And it is sometimes easier than using frontend (which can sometimes be trickier, when it freezes too much).

As mentioned elsewhere,

gdiff := (f,x)->thaw(value(subs(x=freeze(x),Diff(f,x)))): #
gdiff(5*x^2+y,x^2);

(The pre tag is acting up! It looks good in the editor, but is lost on submission.)

acer

First, you should lose the habit of loading a package using `with`, and then using its exports inside a proc.

Instead, either use the full name inside the proc, or use `uses` or `use.

For example you could put the line,

uses LinearAlgebra:-Modular;

at the beginning of your proc, and remove that `with` call altogether.

Next, avoid a mismatch in datatypes. Try changing the last argument of `Create` from ('integer')[] to simply 'integer'. Alternatively, insert datatype=integer[kernelopts(wordsize)/8] as a last argument to the Matrix call where TestMatrix is created.

acer

It looks as if you may be getting bitten by "premature evaluation".

You pass X(a,b) to Optimization:-Maximize. But, as is Maple's usual behaviour, that argument X(a,b) gets evaluated up front before a or b are assigned numeric values. Your routine X does not appear to be prepared for that symbolic input a,b. The unintended evaluation of X(a,b) prior to parameters a and b getting values (which happens only subsequently, inside the routine X), is premature.

There are a few ways to handle that. One is to have X return unevaluated if a and b are not both numeric.

X := proc(a,b)
local ...
  if not( type(a,numeric) and type(b,numeric) ) then
    return 'procname'(args);
  end if;
  ...
end proc:

Another way is to pass arguments to Maximize in so-called operator form. (See the ?Optimization,General,OperatorForm help-page, and in particular the last Example.) For that form, you'd be passing just X rather than X(a,b), and [.6,.2] rather than [a=.6,b=.2], etc. You'd also need to read the section on passing the constraints as a list of procedure(s).

Another way that might work better is to pass 'X'(a,b) so as to delay evaluation.

This also comes up with plot, fsolve, evalf/Int, etc.

acer

> fsolve(unapply(hite(t)-11853,t),0..1000);
                               33.00303938

> fsolve(t->hite(t)-11853);
                               33.00303938

In Maple 13, you could call dsolve/numeric using 'ground' as a 'parameter'. See ?dsolve,numeric,IVP for explanation of the parameters option.

You might also have a look at the ?dsolve,numeric,Events help-page. That might be what you'd call the "elegant" way to do this sort of thing.

acer

A flexible tool for this is verify,list.

See a recent usage example by Joe here (including for float entries)

acer

Yes, look at the module help-page. That's what you should use to create a package.

Look also at the Advanced Programming Manual (available here) which has material on this in section 2.3 and chapter 2 in general.

This comment might also be of some (lesser) use.

acer

By default you cannot write to the Maple system archives, so that you cannot inadvertantly clobber their contents.

First create a writable personal archive of your own, using LibraryTools:-Create or march. Then either prepend its location to libname, or set savelibname, so that your subsequent calls to savelib will use that new, personal archive.

If you are having problems with a routine such as savelib, you can try both reading its help-page as well as following some of the cross-references in its See Also section.

acer

The square-bracket subindexing notation provides this for Vectors, Matrices, and Arrays.

> A:=<1,2,3,4,5>:

> A[1..3];
                                      [1]
                                      [ ]
                                      [2]
                                      [ ]
                                      [3]
 
> A[..3];
                                      [1]
                                      [ ]
                                      [2]
                                      [ ]
                                      [3]
 
> A[1..-3];
                                      [1]
                                      [ ]
                                      [2]
                                      [ ]
                                      [3]

> A[2..4];
                                      [2]
                                      [ ]
                                      [3]
                                      [ ]
                                      [4]

acer

In Maple 13, you can use ~ to modify the minus (-) operator.

`#msub(mi("x"),mi("coord"))` -~ `#msub(mi("y"),mi("bar"))`;

In Maple 12 and earlier, you can use map instead.

map(`-`, `#msub(mi("x"),mi("coord"))`, `#msub(mi("y"),mi("bar"))` );

acer

Do you mean that you want all computations to be done modulo 26? If that means linear algebra computations then you can use LinearAlgebra:-Generic. I don't know a convenient way to get it automatically for all scalar arithmetic except by creating your own package with exported/overloaded operators.

acer

You could start by reading this. Then, if you decide to go with alpha-beta pruning, you might try studying this. After that, you could work on a (static) position evaluator.

It is an interesting question: to what degree position heuristics matter in an effective Go position evaluator (relative, say, to how much they do in a chess position evaluator).

acer

See ?updates,Maple9,compatibility but look at that help-page in your actual Maple, in either the Classic or commandline (TTY) interfaces of Maple 13, or in any interface of Maple 9 through 12.

There it explains that x*x does not simplify to x^2 inside a procedure body because `x` might be a function call or something that returns a random result (and anyone who bothered to enter x*x presumably would want two distinct random results multiplied together, rather than a single result that gets squared).

In the Standard GUI of Maple 13 or the Online Help the input in that explanation is itself automatically simplified from x*x to x^2, so it reads as "x^2 does not automatically simplify to x^2". This is my favourite bug of the month. I will submit an SCR against it.

acer

> m := module() option package; export f;
> local ModuleLoad;
> ModuleLoad:=proc() print("You are proud user of the Foo-package!");
> end proc:
> end module:
> with(m);
                                      [f]
 
> LibraryTools:-Create("foo.mla");
> libname:="./foo.mla",libname:
> savelib(m);
> restart:
> libname:="./foo.mla",libname:
> with(m);
                   "You are proud user of the Foo-package!"
 
                                      [f]

acer

First 295 296 297 298 299 300 301 Last Page 297 of 339