Hello Lyuka, Namir and any interested parties.

Sorry for the delay (been painting). I manually bumped this thread as the original is way down the list.

Lyuka, thanks for the much improved Ostrowski method code. I have been trying it out.

Firstly, it gets good results in almost all cases, beating many other methods. Also, you have fixed the case for the water equation.

i'll just cover this again for detail,

here is the water vapor pressure from temperature:

Value Vwat(Value t)

{

Value x;

t = t + 273.15;

x = 0;

if (t > 0) {

x = -6096.9385 / t + 16.635794 - 0.02711193 * t + 0.00001673952 * t * t + 2.433502 * log(t);

x = exp(x);

}

return x;

}

which you were solving. i mention this again just to add some background and also to point out the way it is normally solved.

The inverse is called Twat :-) and proceeds usually with a baked in method of newton using both sides:

Value Twat(Value e)

{

Value td = 0.0001;

Value ta = 1e-7;

Value T = 100;

int c = 0;

if (e >= 0) for (;;) {

Value dt = 2 * td * (Vwat(T) - e) / (Vwat(T + td) - Vwat(T - td));

T -= dt;

++c;

if (fabs(dt) < ta) break;

}printf("twat count = %d\n", c);

return T;

}

which gives good results for this special case.

now to give some results of your latest code against others in my test:

37 iterations

solve vwat=1e-5 in [-273.150000, 100.000000] with brentRoot = -106.310044

100 iterations

solve vwat=1e-5 in [-273.150000, 100.000000] with secantRoot = -1.#IND00

8 iterations

solve vwat=1e-5 in [-273.150000, 100.000000] with ridderRoot = -106.310044

ost iterations = 19

solve vwat=1e-5 in [-273.150000, 100.000000] with ostRoot = -106.310045root not bracketed

solve exp(6x-x^4-1)=1 in [0.000000, 2.000000] with brentRoot = 0.000000

100 iterations

solve exp(6x-x^4-1)=1 in [0.000000, 2.000000] with secantRoot = -1.#IND00

4 iterations

solve exp(6x-x^4-1)=1 in [0.000000, 2.000000] with ridderRoot = 1.757772

ost iterations = 9

solve exp(6x-x^4-1)=1 in [0.000000, 2.000000] with ostRoot = 1.757772root not bracketed

solve sin(x)-x=1 in [0.000000, 6.000000] with brentRoot = 0.000000

6 iterations

solve sin(x)-x=1 in [0.000000, 6.000000] with secantRoot = -1.934563

9 iterations

solve sin(x)-x=1 in [0.000000, 6.000000] with ridderRoot = -1.934563

ost iterations = 9

solve sin(x)-x=1 in [0.000000, 6.000000] with ostRoot = -1.9345631 iterations

solve (x-1)^2=1 in [-2.000000, 2.000000] with brentRoot = 2.000000

0 iterations

solve (x-1)^2=1 in [-2.000000, 2.000000] with secantRoot = 2.000000

0 iterations

solve (x-1)^2=1 in [-2.000000, 2.000000] with ridderRoot = -1.#QNAN0

solve (x-1)^2=1 in [-2.000000, 2.000000] with ostRoot = 2.000000root not bracketed

solve tan(x)-1/x=0 in [1.000000, 4.000000] with brentRoot = 1.000000

13 iterations

solve tan(x)-1/x=0 in [1.000000, 4.000000] with secantRoot = -3.425618

5 iterations

solve tan(x)-1/x=0 in [1.000000, 4.000000] with ridderRoot = 3.425618

ost iterations = 6

solve tan(x)-1/x=0 in [1.000000, 4.000000] with ostRoot = 3.42561829 iterations

solve (x-1)^5=0 in [0.000000, 1.500000] with brentRoot = 1.000000

100 iterations

solve (x-1)^5=0 in [0.000000, 1.500000] with secantRoot = 1.000000

23 iterations

solve (x-1)^5=0 in [0.000000, 1.500000] with ridderRoot = 1.000000

ost iterations = 8

solve (x-1)^5=0 in [0.000000, 1.500000] with ostRoot = 1.02056129 iterations

solve x^2-10000x+1=0 in [-1.000000, 1.000000] with brentRoot = 0.000100

3 iterations

solve x^2-10000x+1=0 in [-1.000000, 1.000000] with secantRoot = 0.000100

2 iterations

solve x^2-10000x+1=0 in [-1.000000, 1.000000] with ridderRoot = 0.000100

ost iterations = 2

solve x^2-10000x+1=0 in [-1.000000, 1.000000] with ostRoot = 0.000100

you can see the improved Ostrowski method gets good results, but often with a few more iterations than ridders. ridders is fooled by my (x-1)^2-1 quadratic when i gave bad bounds.

bounds are generally a problem with black box solvers since how is one to know good bounds to start?

anyhow, Ostrowski struggles with a very flat curve at (x-1)^5. the other methods get 1.00000 but Ostrowski stops at 1.020561, which is not so good.

i havent tried Namir's 4th order Ostrowski method. would that be better at this?

thanks for the input,

-- hugh.