5

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

Consider the following scenario:

  • expression f with 2 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 a way to achieve this?

Edit:

The step from 1 / (1 + a/b) to 1 / (1 + c) can be achieved by calling

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

So a better formulated question is:

Is there a way to tell MATLAB to 'simplify' b / (a + b) into 1 / (1 + a/b)?

Just calling simplify(b / (a + b) makes no difference.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Fugu_Fish
  • 131
  • 2
  • 10
  • What you want is first a simplification of the original expression, as far as I know MATLAB can do that, the second thing you want is a transformation of variables. I'm not sure MATLAB can do that, as its primary function is numerical calculations. Symbolic stuff such as this is better left to dedicated symbolic programs (such as MAPLE). – Adriaan Sep 13 '16 at 12:07
  • @Adriaan Do you know how to do this simplification? Calling `simplify(f)` makes no difference. If I get it to the 'second' form `subs(f,a/b,c)` results in what i need. – Fugu_Fish Sep 13 '16 at 12:16

1 Answers1

5

Simplification to your desired form is not automatically guaranteed, and in my experience, isn't likely to be achieved directly through simplify-ing as I've noticed simplification rules prefer rational polynomial functions. However, if you know the proper reducing ratio, you can substitute and simplify

>> 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)

And then re-substitute without simplification, if desired:

>> 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)
TroyHaskin
  • 8,361
  • 3
  • 22
  • 22