Maxima: Transforming solutions obtained by linsolve.
Subject: Maxima: Transforming solutions obtained by linsolve.
From: Barton Willis
Date: Mon, 19 Nov 2007 17:26:06 -0600
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)
>
>);
>
>
>
>
>>
>> -----maxima-bounces at math.utexas.edu wrote: -----
>>
>> >To: maxima at math.utexas.edu
>>
>> From: Constantine Frangos <cfrangos at telkomsa.net>
>>
>> >Sent by: maxima-bounces at math.utexas.edu
>> >Date: 11/17/2007 03:45AM
>> >Subject: Maxima: Transforming solutions obtained by linsolve.
>> >
>> >I am using linsolve() for the solution of linear equations. For
>example:
>> >
>> >
>> >(%i513) ysol : linsolve([a11*x1+a12*x2+a13*x3],[x1,x2,x3]);
>> >
>> >(%o513) [x1 = -(%r1*a13+%r2*a12)/a11,x2 = %r2,x3 = %r1]
>> >(%i514)
>> >
>> >I want to transform the obtained solution to the following form:
>> >
>> >xsol = A . r
>> >
>> >where r = matrix([%r1],[%r2])
>> >
>> >and A = matrix([-a13/a11,-a12/a11],[0,1],[1,0])
>> >
>> >Its not clear how to construct or extract the matrix A (and the matrix
>r)
>> >from the list ysol.
>> >
>> >I could not extract the %r1 and %r2 as these seem to be different each
>> >time
>> >linsolve() is called, eg %r3, %r4, etc
>> >
>> >Any assistance would be appreciated.
>> >
>> >TIA
>> >
>> >C. Frangos.
>> >_______________________________________________
>> >Maxima mailing list
>> >Maxima at math.utexas.edu
>> >http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>--
>Constantine Frangos, Pr.Eng.
>Professor
>Dept. of Mathematics and Statistics
>University of Johannesburg
>Auckland Park Kingsway Campus
>P O Box 524
>Auckland Park
>Johannesburg 2006
>South Africa
>
>Tel: +27-11-559-2452
>Fax: +27-11-559-2832
>e-mail: cfrangos at uj.ac.za , cfrangos at telkomsa.net