I have a function of two variables $f(x,y)$ that I know I can be expressed in the form of a single variable $z=x/y$. Is there a way to write the function in terms of $z$ easily/in an automised fashion in mathematica?

To demonstrate, let $$f(x,y) = \frac{\sqrt{xy + x^2}}{-y-x+\sqrt{xy + x^2}}.$$ Then, for $x>0$, we have $$f(x,y) = g(x/y) = \frac{\sqrt{1 + y/x}}{-y/x-1+\sqrt{1 + y/x}}.$$

In practice, in mathematica I am dealing with a much larger expression of $x$ and $y$ otherwise can do everything by hand.

Is there a way to automate the re-writing of an expression in terms of two variables as a function of only one, as described above?

  • 2
    $\begingroup$ If $z=x/y$ then $x=y z$, so you can use replace all x by y z to eliminate x. If the expression can really be rewritten, then the remaining y should cancel out. Here this requires additionally that $y>0$, so expr /. x -> y z // FullSimplify[#, y > 0] & does the trick $\endgroup$
    – Lukas Lang
    May 3 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.