[newbie] solving overspecified system of linear equations




Hugo Coolens <coolens at kahosl.be> writes:

> wow, great, that's just what I needed!
>
> sincerely,
> Hugo

Please reply to the maxima list.

>
>
> On Fri, 11 May 2012, Leo Butler wrote:
>
>> Hugo Coolens <coolens at kahosl.be> writes:
>>
>>> Coudl anyone on this list tell me how I can solve an overspecified system
>>> of linear equations in Maxima
>>
>> How about
>> (%i1) linsolve([x+y+z=1,x+y=1,z=0,x=0],[x,y,z]);
>>
>> solve: dependent equations eliminated: (2)
>> (%o1)                        [x = 0, y = 1, z = 0]
>>
>> and
>>
>> (%i2) linsolve([x+y+z=1,x+y=1,z=0,x+y=0],[x,y,z]);
>> (%o2)                                 []
>>
>> There are ways to 'solve', in an error minimizing sense, a system of
>> overdetermined and inconsistent equations. The most common way is least
>> squares regression. For example:
>>
>> (%i1) load (lbfgs);
>> (%o1)           /usr/share/maxima/5.27.0/share/lbfgs/lbfgs.mac
>> (%i2) eqs:[x+y+z=1,x+y=1,z=0,x+y=0]$
>>
>> (%i3) fom:subst("="="-", eqs);
>> (%o3)                [z + y + x - 1, y + x - 1, z, y + x]
>> (%i4) fom: fom.fom;
>>                               2    2          2              2
>> (%o4)           (z + y + x - 1)  + z  + (y + x)  + (y + x - 1)
>> (%i5) lbfgs(fom,[x,y,z],[0,0,0],1e-4,[1,0]);
>> *************************************************
>>  N=    3   NUMBER OF CORRECTIONS=25
>>       INITIAL VALUES
>> F=  2.000000000000000D+00   GNORM=  6.000000000000000D+00
>> *************************************************
>>
>>   I  NFN     FUNC                    GNORM                   STEPLENGTH
>>
>>   1    3     6.034482758620692D-01   1.462979547282512D-01
>>   7.758620689655173D-02
>>   2    4     6.019883621059441D-01   1.110925645530035D-01
>>   1.000000000000000D+00
>>   3    5     6.000000000000000D-01   5.606351459942525D-16
>>   1.000000000000000D+00
>>
>> THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
>> IFLAG = 0
>> (%o5)                     [x = 0.3, y = 0.3, z = 0.2]
>>
>>
>>
>> -- 
>> Leo Butler                <l_butler at users.sourceforge.net>
>> SDF Public Access UNIX System -   http://sdf.lonestar.org
>>
>

-- 
Leo Butler                <l_butler at users.sourceforge.net>
SDF Public Access UNIX System -   http://sdf.lonestar.org