Maxima: how to replace variables in equations
Asked Answered
W

1

6

I'm trying to write down some notes of my work. The way Maxima would simplify my work is that once I write bunch of equations and I want to change the definition of a variable, I do it and re-evaluate the entire file.

Here is an example of what I'm trying to accomplish:


Question 1: I have a system of equations and all I want from Maxima is just variables replacement.

eq1: x=a+b+c
eq2: y=d+e+f
eq3: x+y=0

How do I get Maxima to output

eq3: a+b+c+d+e+f = 0

So in the future if I want x to be a+b-c, I just change it and re-evaluate


Question 2: Similar to before but a bit more complex

eq1: x=a+b+c
eq2: y=d+e+f
eq3: x=y
eq4: a+s+e=0

How do I get Maxima to output

eq3 a+b+c=d+e+f

How do I get Maxima to solve eq1 for a and solve eq2 for e and output

eq4: x-b-c+s+y-d-f = 0

Thank you in advance for your help, Guido

Wavellite answered 10/2, 2017 at 16:36 Comment(0)
E
9

I think subst and solve can handle the operations you want here.

(%i1) eq1: x=a+b+c;
(%o1)                            x = c + b + a
(%i2) eq2: y=d+e+f;
(%o2)                            y = f + e + d
(%i3) eq3: x+y=0;
(%o3)                              y + x = 0
(%i4) subst ([eq1, eq2], eq3);
(%o4)                      f + e + d + c + b + a = 0

OK, now here's your second example. Note that solve returns a list of equations.

(%i5) eq3: x=y;
(%o5)                                x = y
(%i6) eq4: a+s+e=0;
(%o6)                            s + e + a = 0
(%i7) subst ([eq1, eq2], eq3);
(%o7)                        c + b + a = f + e + d
(%i8) solve (eq1, a);
(%o8)                           [a = x - c - b]
(%i9) solve (eq2, e);
(%o9)                           [e = y - f - d]
(%i10) append (%o8, %o9);
(%o10)                  [a = x - c - b, e = y - f - d]
(%i11) subst (%o10, eq4);
(%o11)                   y + x + s - f - d - c - b = 0

Maxima's solve function is not too powerful; there are many kinds of equations it cannot solve. But it can solve linear equations.

Eratosthenes answered 11/2, 2017 at 5:44 Comment(2)
thank you very much, Robert! I didn't know subst could have been used in that way. Really appreciated your helpWavellite
It isn't spelled out very clearly, but basically if you have an expression with a variable and want to substitute a variable with a value, you would do something like subst(x = 3, x + 2);, which would return 5.Hyposensitize

© 2022 - 2024 — McMap. All rights reserved.