Rewrite the symbolic expression in terms of a specific subexpression

I need to rewrite a symbolic expression in terms of a specific subexpression.

Consider the following scenario:

  • expression fwith two variables a,b
  • subexpression c = a / b

    syms a b c
    f = b / (a + b) % = 1 / (1 + a/b) = 1 / (1 + c) <- what I need
    

Is there any way to achieve this?

Edit:

A step from 1 / (1 + a/b)to 1 / (1 + c)can be reached by calling

subs(1 / (1 + a/b),a/b,c)

So, it is better to formulate the question:

Is there any way to tell MATLAB to "simplify" b / (a + b)in 1 / (1 + a/b)?

Just a challenge simplify(b / (a + b)does not matter.

+4
source share
1 answer

, , , simplify -ing, , . , ,

>> syms a b c
>> f = b / (a + b);
>> simplify(subs(f,a,c*b))
ans =
1/(c + 1)

>> simplify(subs(f,b,a/c))
ans =
1/(c + 1)

:

>> subs(simplify(subs(f,a,c*b)),c,a/b)
ans =
1/(a/b + 1)

>> subs(simplify(subs(f,b,a/c)),c,a/b)
ans =
1/(a/b + 1)
+5

Source: https://habr.com/ru/post/1654456/


All Articles