Dear all,
First, a couple of numbers to introduce the question

cos(0.1)~0.995004165278025766095561987803870294838576225415084035959352...

### NOTE all results are on 32-bit Ubuntu 15.10
To compare
a helper:

function string as_string (scalar x)

sprintf s "%.15g",x

return s

end function


1) 

x={0.1}

eval as_string(fdjac(x,sin(x)))

0.99500416778028


2)


set fdjac_quality 1

eval as_string(fdjac(x,sin(x)))

0.995004165451974


3)


set fdjac_quality 2

eval as_string(fdjac(x,sin(x)))

0.995004163123667


A home-backed thing inspired by fdjac help:


A helper:

function scalar feval (string fun, scalar x)

return @fun

end function


The main:


function scalar sdj2 (string f, scalar x)

if abs(x)>10^3

h = 10^3*sqrt(x/1000*$macheps)

else

h=10^(3)*sqrt($macheps)

endif

z = (8*(feval(f,x+h)-feval(f,x-h)) - (feval(f,x+2*h)-feval(f,x-2*h)))/(12*h)

sz = as_string(z)

return z

end function


We have


eval as_string(sdj2("sin(x)",0.1))

0.995004165277274

recall:

0.995004165278025766


In theory, fdjac should be better,

since it uses the same formula as sdj2()

and it should optimize the step h,

but...

Oleh