Information Technology Reference
In-Depth Information
6.3.8
Maple
Maple is a complete problem-solving environment for symbolic calculations. Sym-
bolic in this context means manipulating mathematical expressions, not just num-
bers. For example, Maple can calculate the integral of cos x to be sin x and
differentiate sinh x to get cosh x . Maple is also equipped with the widely used NAG
libraries for efficient numerical computations.
A particularly attractive feature of Maple is that you can write interactive scien-
tific reports with formulas, text, and plots. The report can be read as is, but the reader
can also change Maple commands (formulas, equations, etc.) and view the conse-
quences of such changes. This encourages explorative and interactive investigations
of scientific problems.
Maple is a complete programming language. As in Matlab and Python, variables
are not explicitly typed and there are many high-level commands, making Maple
programs compact.
The bridge between Algorithm 6.2 and a Maple function is short:
Trapezoidal := proc(a,b,f,n)
local h, s, x, i:
h := (b-a)/n:
s := 0: x := a:
for i from 1 to n-1 do
x:=x+h:
s := s + f(x):
od:
s:=s+0.5 * f(a) + 0.5 * f(b):
s:=h * s:
s;
end:
Maple performs symbolic computations. That is, (b-a)/n is not a number unless
a , b ,and n are assigned numbers; if these arguments are assigned mathematical
expressions, (b-a)/n remains an expression, i.e., a mathematical formula instead
of a number. In the present case, a , b ,and n are numbers, so the operations in the
trapezoidal function are numerical computations.
A test function f1 to be integrated is defined by
f1 := x -> exp(-x * x) * log(1+x * sin(x));
The numerical integration of f1 is now carried out by
q := Trapezoidal(0, 2, f1, 1000)
This code runs very slowly. Repeating it 10 times and multiplying the CPU time by
1,000 (corresponding to 10,000 repetitions as we have used for all previous CPU
time comparisons) showed that Maple required more than 600 times the CPU time
of the Fortran 77 implementation! We should add that the speed of Maple varied
greatly (up to a factor of 4) between different executions.
The reason why the implementation of Algorithm 6.2 runs so slowly in Maple
is that Maple code is interpreted. Long for loops are, in some sense, a misuse of
Maple. One should either implement such loops with numerical computations in
Search WWH ::




Custom Search