wrong result from function solve



On 04/18/2012 12:30 PM, Sara Pashmin wrote:
> I waned to solve 3 equations, which are equal to each other:
>
> kill(all);
> z:0.01;
> ratprint:false;
> eq1:(2.15-x)*(y-x)-((y-x)^2/2)$
> eq2:(2.2-y)*(z-y)-((z-y)^2/2)$
> eq3:2.15*x-(x^2/2)$
eq1, eq2 and eq3 are not equations, but expressions.
> solve([
>            eq1=eq3 ,
>            eq2= eq3 ,
>            t=eq3],
>            [x,y,t]),numer;
>
> The answer is:
> [[x=4.330183106910809,y=4.359953703703703,t=-.06534923339011925],[x=4.29664660361135,y=.006712608473711077,t=.007204789943107004],[x=-
> .03018312788515193,y=4.359953703703703,t=-.06534923339011925],[x=.003353680604145053,y=.006712608473711077,t=.007204789943107004]]
>
> I checked two terms of results but unfortunately the answers of
> equations are not the same that means the equations are not equal to
> each other:
>
>
> x:.003353680604145053 ;
> y:.006712608473711077 ;
> t:.007204789943107004 ;
> eq1=(2.15-x)*(y-x)-((y-x)^2/2);
> eq2=(2.2-y)*(z-y)-((z-y)^2/2);
> T=2.15*x-(x^2/2);
>
> (%o11) (2.15-x)*(y-x)-(y-x)^2/2=.007204788950103592
> (%o12) (0.01-y)*(2.2-y)-(0.01-y)^2/2=.007204790914096299
> (%o13) 2.15*x-x^2/2=.007204789712114554
The answer is OK, up to 7 decimal places. A numerical result has always 
an error. The moment you wrote 0.01, 2.2 and 2.15 in your definition of 
the expressions, you already introduced numerical errors, because those 
numbers can not be represented exactly in a binary system. You could 
have written those number in exact form:
   1/100, 22/10 and 215/100
but in this example solve is not able to find an exact solution and it 
will use floating point anyway. Writing those three numbers in "big 
float notation":
   1b-2, 2.2b0, 2.15b0
give higher accuracy, but apparently solve always uses single 
floating-point precision regardless of the equations. Perhaps there is a 
way to force solve to use big floating-point precision, but I'm not 
aware of it.

Some comments:
if you save the solutions into a variable, it will then be easier to 
check the results, without having to write
again the equations or the results:

(%o23) [[x = 4.330183106910809, y = 4.359953703703703,
t = - .06534923339011925], [x = 4.29664660361135,
y = .006712608473711077, t = .007204789943107004],
[x = - .03018312788515193, y = 4.359953703703703,
t = - .06534923339011925], [x = .003353680604145053,
y = .006712608473711077, t = .007204789943107004]]

(%i24) eq1,sol[4];
(%o24)                 .007204788950103593

(%i25) eq2,sol[4];
(%o25)                 .007204790914096299

(%i26) eq3,sol[4];
(%o26)                 .007204789712114554

Regards,
Jaime