I don't know enough about the Maple architecture to comment on speed of execution. However, here are a few things to make Maple go faster:
Use floating point where possible
Maple by default tries to keep results in exact form. For example the following expression
would be kept in its exact form, which is really slow. To speed things up you can make Maple evaluate the expression into a floating point number by
evalf (sin (Pi/2))
This can result is small improvement without doing a lot of work.
Evalhf is a procedure that can execute another procedure or a statement using hardware floating point arithmetic. See ?evalhf
for more details.
Here is an example from one of the samples in Maple 10.
WaveGen := proc(
local i::posint, j::posint, tot::float, t::float, deltaT::float;
for i from 1 to Npoints do
t := evalf (i/SampleFreq);
for j from 1 to nc do
tot:= tot + evalf (amps[j]*(sin(2*Pi*freqs[j]*t)));
SigData[i] := tot;
This procedure can be called using evalhf as
evalhf (WaveGen (5, amps, freqs, Npoints, Fs, var(SigData)));
Compile the procedure
You can also use the compiler to compile the procedure. The above procedure would be compiled using:
c_WaveGen := Compiler:-Compile (WaveGen):
Then you can execute the c_WaveGen procedure, which calls the compiled code.
c_WaveGen (5, amps, freqs, Npoints, Fs, SigData));
To get the sense of the possible speedup, here are timing for the SignalGeneration
example in Maple 10.
- Maple proc - 121 seconds
- Evalhf - 0.484 seconds
- Compile - 0.093 seconds
To see the example, go to the Help Menu
, then Take a tour
. From the worksheet, you can click on the Wave Generation
link to bring up the example.
Hope this helps,
Applications Engineer, Maplesoft