Two newbie questions



Replies inline below.

On Tue, Aug 28, 2012 at 7:39 AM, Amadeus W.M. <amadeus84 at verizon.net> wrote:

> I have two newbie questions:
>
> 1) I want to define a linear operator E (expectation), so I do
>
> declare(E,linear);
>
> Then E(2*x+3*y) = 2 E(x) + 3 E(y) as expected. But I have to do things
> like E(a*x + b*y) where a and b are constant. Maxima outputs E(ax) + E
> (by). How do I make it tread a and b as constants?
>

declare([a,b],constant)

2) I have an expression of the form f(x,y,z) + g(x,y,z) + h(x,y,z) where
> f, g and h are polynomials in x, y, z. How do I collect the like terms in
> x, say? That is, how do I make Maxima treat y and z as constants and
> treat f+g+h as a polynomial in x only? It's probably related to the first
> question.
>

You can express something as a polynomial in x using rat(expr,x):

(%i1) expr: (x^2-1)*y + (x+y+z)*(x-y+1);
(%o1) (-y+x+1)*(z+y+x)+(x^2-1)*y
(%i2) rat(expr,x);      <<< express as polynomial in x
(%o2)/R/ (y+1)*x^2+(z+1)*x+(-y+1)*z-y^2
(%i3) rat(expr,y);      <<< express as polynomial in y
(%o3)/R/ -y^2+(-z+x^2)*y+(x+1)*z+x^2+x
(%i4) rat(expr,z);      <<< express as polynomial in z
(%o4)/R/ (-y+x+1)*z-y^2+x^2*y+x^2+x
(%i5) expand(expr);     <<< expand fully
(%o5) -y*z+x*z+z-y^2+x^2*y+x^2+x

Let us know if you have other questions!

            -s