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
有帮助吗?

解决方案

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)

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top