-1

I have a code that works as non linear system equation solver. I have so much trouble with a command that goes like this:

newt[0]:=[-2.,20]:

I don't know what does that dot works there! I thought it may be for showing that it is -2.0, but there is no reason to use that when by default -2 = -2.0.

Can anyone help me with this?

MrSinaRJ
  • 57
  • 13

2 Answers2

0

The dot forces float calculations

It is not correct that by default -2 = -2.0. There is a very big difference for Maple in how it calculates: if you use -2 it calculates exacts (arithmetic expressions) while -2.0 tells Maple to calculate with floats (numerical expressions).

The two expressions -2.*sqrt(5) and -2*sqrt(5.) are quite different in how Maple handles them, if you notice the float position! For the first example, the square root is calculated arithmetically, while in the second example it is calculated numerically!

This can be a very big deal for some calculations; both with regards to speed and precision, and should be considered carefully when one wants to do complicated computations.


Speed example: Calculate exp(x) for 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 especially the huge difference in memory used. This is an example of when using floats gives worse performance. On the contrary, if we are just approximating anyways, numerical approximation is much 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: For precision, things can go very wrong if one is 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!!!)
Therkel
  • 1,379
  • 1
  • 16
  • 31
-1

After a little working with that I finally found what it does!

short answer: it calculate the result of expression where those 2 integers are inputs.

extended answer:(example)

given 2 functions, we want to calculate Jacobin matrix for this equation system

with(linalg);
with(plots);
f := proc (x, y) -> (1/64)*(x-11)^2-(1/100)*(y-7)^2-1;
g := proc (x, y) -> (x-3)^2+(y-1)^2-400;

then we put functions in vector:

F:=(x, y) -> vector([f(x,y),g(x,y)]);
F(-2 ,20)
F(-2.,20)

result will be this:

[-79/1600 -14]
[-0.049375000 -14]
MrSinaRJ
  • 57
  • 13