Bug - Messages

#1 Posted: 11/9/2010 5:12:30 PM
philippe dalet

philippe dalet

18 likes in 34 posts.

Group: User

Hello,

I've found a bug on the solve function.



ess.sm

best regards

Philippe DALET
FRANCE
#2 Posted: 11/9/2010 7:37:56 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello Philippe,

I do not think this is a bug. You just bumped into some numerical problems.
For instance, try to increase the number of decimal places:

[MATH=eng]res←solve(0.05-x-x^2*1/K,x)[/MATH] [MATH=eng]res=mat(0.00126962,0.00040433,2,1)[/MATH]
[MATH=eng]x←el(res,1)[/MATH] [MATH=eng]0.05-x-x^2*1/K=-0.04391025[/MATH]
[MATH=eng]x←el(res,2)[/MATH] [MATH=eng]0.05-x-x^2*1/K=0.04020022[/MATH]

Not so good, isn't it. That is a problem when you have the function with a rational expression and small value in the denominator (division with K) and the roots close to zero. This is a polynomial of the second degree and when you plot this function you could see that there are two roots, one positive and one negative. Let's try the "roots" this time (guess values are important here):

[MATH=eng]res1←roots(0.05-X-X^2*1/K,X,-1)[/MATH]
[MATH=eng]res1=-0.00094148[/MATH] [MATH=eng]0.05-res1-res1^2*1/K=2.07062052*10^{-17}[/MATH]
[MATH=eng]res2←roots(0.05-X-X^2*1/K,X,1)[/MATH]
[MATH=eng]res2=0.00092408[/MATH] [MATH]0.05-res2-res2^2*1/K=-1.47531712*10^{-16}[/MATH]

For this problematic equation, the transforming of the equation will give a slight better results (not much better, but "solve" will did its best):

[MATH=eng]res←solve(K*(0.05-x)-x^2,x)[/MATH] [MATH=eng]res=mat(0.00126962,0.00040433,2,1)[/MATH]
[MATH=eng]K*(0.05-el(res,1))-el(res,1)^2=-0.00000076[/MATH]
[MATH=eng]K*(0.05-el(res,2))-el(res,2)^2=0.0000007[/MATH]

Moreover, you could try to use the searching interval:
[MATH=eng]res←solve(K*(0.05-x)-x^2,x,0,1)[/MATH]
[MATH=eng]res=0.0009240784783[/MATH]
[MATH=eng]K*(0.05-res)-res^2=3.5504197442949*10^{-16}[/MATH]
(negative root could not find?)

You could try "roots" here as well. The results will be the same (-0.00094148,0.00092408). These are very close to the analytical results.

"solve" and "roots" use the different numerical algorithms and solving the nonlinear equations could be troublesome sometimes. Here you have both roots close to zero and that could make troubles.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
  • New Posts New Posts
  • No New Posts No New Posts