access results of linsolve



A safer alternative to list[index] is inpart(list, index). Another
possibility is
to use substitution:

 (%i1) sol : linsolve([C1*3-2,C2*1+4],[C1,C2]);
 (%o1) [C1=2/3,C2=-4]

 (%i2) subst(sol, [C1, C2, C1 - C2]);
 (%o2) [2/3,-4,14/3]

Why is inpart(list, index) safer than list[index]?

 (%i5) ssol : linsolve([C1*3-2,C2*1+4],[C1,C2]);
 (%o5) [C1=2/3,C2=-4]

Not what we want:

 (%i6) ssol[1];
 (%o6) ssol[1]

OK

 (%i7) inpart(ssol,1);
 (%o7) C1=2/3

Barton

-----maxima-bounces at math.utexas.edu wrote: -----

>To:?Michael?Anderl?<michael.anderl at gmail.com>
>From:?reyssat?<eric.reyssat at math.unicaen.fr>
>Sent?by:?maxima-bounces at math.utexas.edu
>Date:?12/15/2009?03:41PM
>cc:?maxima at math.utexas.edu
>Subject:?Re:?[Maxima]?access?results?of?linsolve
>
>Michael?Anderl?a??crit?:
>>?output:
>>?[C1=2/3,C2=-4]
>>
>>?how?to?access?C1?and?C2?
>>
>use?list[index]?to?extract?an?element?from?a?list,?and?the?function?rhs
>to?get?the?right?hand?side?(lhs?for?left)?of?an?equation?:
>rhs(%[1]);
>gives?2/3?since?it?is?the?right?hand?side?of?the?first?term?of?the?last
>computed?result?(%)
>This?is?C1.
>
>Eric
>_______________________________________________
>Maxima?mailing?list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima