Question

I'm having trouble finding out how to do this:

x=a+b
y=c+d
z=x*y

I would like the output to be

z=ac+ad+bc+bd

not

z=xy
Was it helpful?

Solution

Like this?

(%i1) x: a+b;
(%o1)                                b + a
(%i2) y: c+d;
(%o2)                                d + c
(%i3) z: x*y;
(%o3)                           (b + a) (d + c)
(%i4) z: expand (z);
(%o4)                        b d + a d + b c + a c
(%i5) 

Assignment in maxima is done by :, not = (which is used for checking for equality)

OTHER TIPS

Actually, to get the output he's requesting without assigning a lot of variables, you can just do this:

(%i1) z = x*y, x = a+b, y = c+d, expand;
(%o1) z = b d + a d + b c + a c

This is an old question, but the canonical solution in my opinion is the subst() function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top