I would like to write an expression of certain variables into a different form, by using a set of definitions. This may sound like a silly question, yet I really am troubled on how to get on. I'll give out an example, to clarify. Say I have:


And that I would like to define the following factors:




How can I ask mathematica to write $r$ in this form:


By hand, this is obtained by simply dividing the two sides of the fraction by $v$. How can this be managed with Mathematica?


3 Answers 3


You can use Eliminate to remove the unwanted variable, and then solve for r.

Solve[#, r] &@
 Eliminate[{r == s/(c + v), rs == s/v, oc == c/v}, {s, c, v}]
(*{{r -> rs/(1 + oc)}}*)

You can just substitute $s$ and $c$ as functions of $r_s$ and $o_c$. First we write the original expression,

expr = r == s/(c + v);

Then we obtain substitution rules from the definitions of $r_s$ and $o_c$,

subs = Flatten@Solve[{rs == s/v, oc == c/v}, {s, c}]//Simplify
(* {s -> rs v, c -> oc v} *)

And finally, we can apply the rules to the expression:

expr /. subs // Simplify
(* r == rs/(1 + oc) *)

I have two answers for this example. The first one:

expr = s/(c + v);
rules = {s/v -> Subscript[r, s], c/v -> Subscript[o, c]};
num = Numerator[expr]/v /. rules;
den = Apart[Denominator[expr]/v] /. rules;

It provides the simplify fraction r_s/(1+o_c) but you had to do part of the math by hand (separating numerator and denominator then putting them back together).

The second answer might suit you better. You are actually seeking to replace s and c in term of new variables, so just do so and simplify:

expr = s/(c + v);
rules2 = {s -> v Subscript[r, s], c -> v Subscript[o, c]};
Simplify[expr /. rules2]

Again you get the same answer, but this time in a more automatic way.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.