MATLAB Answers

Moritz
0

Substitute equation into another one

Asked by Moritz
on 31 Oct 2012
Hi,
I'm wondering whether there is a neat way to substitute an equation into another one.
Example:
1st equation: x*dx*dy+dy*dz*x+z
2nd equation: dx+dz=u
Expected solution: x*dy*u+z
How do I do that? Right now I wrote a script, which can do it (but its 70 lines long and quite slow). Is there an easy solution?
Thank you very much!
Product: Matlab 2012a

  0 Comments

Sign in to comment.

1 Answer

Answer by Argon
on 31 Oct 2012
 Accepted Answer

Like that?
f = sym('x*dx*dy+dy*dz*x+z');
g = sym('dx+dz=u');
simplify(subs(f, 'dx', solve(g, 'dx')))
Of course, it gets harder if your equation is non-linear...

  1 Comment

So simple and so brilliant. Looks like I couldn't see the forest for the trees... Thanks a lot!

Sign in to comment.