i have code works non linear system equation solver. have trouble command goes this:
newt[0]:=[-2.,20]:
i don't know dot works there! thought may showing -2.0
, there no reason use when default -2 = -2.0
.
can me this?
the dot forces float calculations
it not correct default -2 = -2.0
. there big difference maple in how calculates: if use -2
calculates exacts (arithmetic expressions) while -2.0
tells maple calculate floats (numerical expressions).
the 2 expressions -2.*sqrt(5)
, -2*sqrt(5.)
quite different in how maple handles them, if notice float position! first example, square root calculated arithmetically, while in second example calculated numerically!
this can big deal calculations; both regards speed , precision, , should considered when 1 wants complicated computations.
speed example: calculate exp(x)
x = 1,2,...,50000
. (arithmetic > numerical)
codetools:-usage(seq(exp(x),x=1..50000)): # arithmetic
memory used=19.84mib, alloc change=0 bytes, cpu time=875.00ms, real time=812.00ms, gc time=265.62ms
codetools:-usage(seq(exp(1.*x),x=1..50000)): # numerical
memory used=292.62mib, alloc change=0 bytes, cpu time=9.67s, real time=9.45s, gc time=1.09s
notice huge difference in memory used. example of when using floats gives worse performance. on contrary, if approximating anyways, numerical approximation faster.
approximate exp(1)
(numerical > arithmetic)
codetools:-usage(seq((1+1/x)^x,x=1..20000)): # arithmetic
memory used=0.64gib, alloc change=0 bytes, cpu time=39.05s, real time=40.92s, gc time=593.75ms
codetools:-usage(seq((1+1./x)^x,x=1..20000)): # numerical
memory used=56.17mib, alloc change=0 bytes, cpu time=1.06s, real time=1.13s, gc time=0ns
precision example: precision, things can go very wrong if 1 not careful.
f:=x->(pi-x)/sin(x); limit(f(x),x=pi); # arithmetic returns 1 (true value) limit(f(x),x=pi*1.); # numerical returns 0 (wrong!!!)