maxima-bounces at math.utexas.edu wrote on 12/03/2007 08:28:03 AM:
> On Dec 3, 2007 4:20 AM, Adi Shavit <adish at eyetech.jp> wrote:
> > What if my eq has scalar elements too as in
> >
> > eq: a*x+b*y+3*x+9*z-4;
> >
> > Then how do I also extract the free variable, i.e. -4 in your example?
>
> Somehow I knew you were going to ask that.... The simplest way I can
> think of is
>
> block([res: eq], for i in U do res: subst(0,i,res), return(res))
>
> but there's probably a better way....
>
> -s
If Adi wants to convert multiple equations, perhaps augcoefmatrix would be
the way to go:
(%i1) eq: a*x+b*y+3*x+9*z-4;
(%o1) 9*z+b*y+a*x+3*x-4
(%i2) U: [x,y,z];
(%o2) [x,y,z]
(%i3) butlast(l) := reverse(rest(reverse(l)))$
(%i4) block([row : first(augcoefmatrix([eq],U))], [U, butlast(row),
last(row)]);
(%o4) [[x,y,z],[a+3,b,9],-4]
One thing that might be a problem: augcoefmatrix converts big floats to
rationals.
The keepfloat switch doesn't prevent the conversion.
(%i5) eq: a*x+b*y+3*x+9.4b0*z-4$
(%i6) block([row : first(augcoefmatrix([eq],U))], [U, butlast(row),
last(row)]);
`rat' replaced 9.4B0 by 47/5 = 9.4B0
`rat' replaced 9.4B0 by 47/5 = 9.4B0
`rat' replaced 9.4B0 by 47/5 = 9.4B0
(%o6) [[x,y,z],[a+3,b,47/5],-4]
BW