Linsolve: is it correct?



On 5 Sep 2008, Alexander El'bert wrote:

> Hi,
> It is very strange for me:
> (%i1) linsolve(0.9*t-x*t,x);
> (%o2) [x=9/10]
> (%i2) keepfloat:true;
> (%i3) linsolve(0.9*t-x*t,x);
> (%o3) [x=0]
>
> Alexander     

It appears that keepfloat:true screws up linsolve
and is ignored by solve:
A. screws up linsolve:

(%i1)  display2d:false$
(%i2) [globalsolve,programmode];
(%o2) [false,true]
(%i3) block([ratprint:false],
          linsolve([0.9*x + 0.3*y = 2.1,0.3*x -0.5*y = 5.4],[x,y] ) );
(%o3) [x = 89/18,y = -47/6]
(%i4) block([ratprint:false,keepfloat:true],
          linsolve([0.9*x + 0.3*y = 2.1,0.3*x -0.5*y = 5.4],[x,y] ) );
Inconsistent equations:  [2]
 -- an error.  To debug this try debugmode(true);

B. ignored by solve:

(%i5) block([keepfloat:true ],
        solve([0.9*x + 0.3*y = 2.1,0.3*x -0.5*y = 5.4],[x,y] ) );
`rat' replaced -2.1 by -21/10 = -2.1

`rat' replaced 0.9 by 9/10 = 0.9

`rat' replaced 0.3 by 3/10 = 0.3

`rat' replaced -5.4 by -27/5 = -5.4

`rat' replaced 0.3 by 3/10 = 0.3

`rat' replaced -0.5 by -1/2 = -0.5
(%o5) [[x = 89/18,y = -47/6]]

If you are doing float problems, use solve
wrapped in float and turn off ratprint.

As in
(%i7) fsolve(eqns,vars) := (ratprint:false, float(solve(eqns,vars)) );
(%o7) fsolve(eqns,vars):=(ratprint:false,float(solve(eqns,vars)))
(%i8) fsolve(0.9*a - a*x,x);
(%o8) [x = 0.9]
(%i9) fsolve(0.8*x^2 + 2.3*x - 4.3, x);
(%o9) [x = -4.1653941053494,x = 1.2903941053494]

For deeper answers, you need experts in the linsolve code.

Ted Woollett