Maxima: Transforming solutions obtained by linsolve.



Dear Barton,

Thanks for the detailed programming suggestions - much appreciated.

Your explanation on how %rnum_list works together with linsolve, etc is 
useful.  I was not aware of this.

Regards,

C. Frangos.

On Tuesday 20 November 2007 01:26, Barton Willis wrote:
> Maybe you need to look at %rnum_list? Try something like:
>
>   (%i10) mycoefmatrix(listeqns) := coefmatrix(map('rhs,listeqns),
>   %rnum_list)$
>
>   (%i11) linsolve([x+y=1],[x,y]);
>   (%o11) [x=1-%r3,y=%r3]
>
>   (%i12) mycoefmatrix(%);
>   (%o12) matrix([-1],[1])
>
> But %rnum_list changes  when linsolve (or algsys) gets called.
> So you would be better off if your function mycoefmatrix
> called linsolve--something like
>
>   (%i18) mycoefmatrix(eqs,vars) := coefmatrix(map('rhs,
>   linsolve(eqs,vars)), %rnum_list)$
>
>   (%i19) mycoefmatrix([x+y = 42],[x,y]);
>   (%o19) matrix([-1],[1])
>
>   (%i20) mycoefmatrix([x+y = 42],[x]);
>   (%o20) matrix([0])
>
>   (%i21) mycoefmatrix([x+y = 42],[x,y,z]);
>   (%o21) matrix([0,-1],[0,1],[1,0])
>
> Let me know if this doesn't help.
>
> BW
>
> -----Constantine Frangos <cfrangos at telkomsa.net> wrote: -----
>
> >To: Barton Willis <willisb at unk.edu>
>
> From: Constantine Frangos <cfrangos at telkomsa.net>
>
> >Date: 11/19/2007 02:58PM
> >cc: maxima at math.utexas.edu, Jaime Villate <villate at fe.up.pt>
> >Subject: Maxima: Transforming solutions obtained by linsolve.
> >
> >On Saturday 17 November 2007 13:41, Barton Willis wrote:
> >> Try this:
> >>
> >>   (%i1) [x1 = -(%r1*a13+%r2*a12)/a11,x2 = %r2,x3 = %r1]$
> >>
> >>   (%i2) map('rhs,%);
> >>   (%o2) [(-%r1*a13-%r2*a12)/a11,%r2,%r1]
> >>
> >>   (%i3) coefmatrix(%,[%r1,%r2]);
> >>   (%o3) matrix([-a13/a11,-a12/a11],[0,1],[1,0])
> >>
> >> Why map rhs on to the equations?  Consider:
> >>
> >>   (%i4) coefmatrix([x+y=z, x-y=q],[x,y]);
> >>   (%o4) matrix([1,1],[1,-1])
> >>
> >>   (%i5) augcoefmatrix([x+y=z, x-y=q],[x,y]);
> >>   (%o5) matrix([1,1,-z],[1,-1,-q])
> >>
> >> BW
> >
> >Thanks very much for the detailed response. This is exactly what is
> >needed.
> >
> >I am trying to incorporate your idea in a maxima function mycoefmatrix()
> >to
> >be called as follows:
> >
> >xsol1 : linsolve([a11*x1+a12*x2+a13*x3=0],[x1,x2,x3]);
> >
> >(%o20) [x1 = -(%r3*a13+%r4*a12)/a11,x2 = %r4,x3 = %r3]
> >
> >A1 : mycoefmatrix(xsol1);
> >
> >
> >xsol2 : linsolve([a11*x1+a12*x2+a13*x3+a14*x4=0],[x1,x2,x3,x4]);
> >
> >(%o21) [x1 = -(%r5*a14+%r6*a13+%r7*a12)/a11,x2 = %r7,x3 = %r6,x4 = %r5]
> >(%i22)
> >
> >A2 : mycoefmatrix(xsol2);
> >
> >etc............
> >
> >However, I cannot find a maxima method/command  to extract the list r
> >below.
> >
> >Thanks again for the assistance.
> >
> >Regards,
> >
> >C. Frangos.
> >
> >
> >
> >mycoefmatrix(listeqns) := block(
> >
> >[A,B,r,....],
> >
> >/*Determine if %r1, %r2.....  are present in listeqns, and if so extract
> >and
> >place in list r.*/
> >
> >B : map('rhs,listeqns),
> >A : coefmatrix(B,r),
> >
> >return(A)
> >
> >);