# Changing variables algebraically

Suppose one has two functions, $y(x)$ and $z(x)$, and one seeks to obtain $y(z)$ by substituting $x(z)$ into $y(x)$. Can this be done in a single step? Or must $z(x)$ first be inverted independently? For the sake of illustration, suppose the functions consist of transcendental functions combined by the elementary operations of addition, subtraction, multiplication, division, and exponentiation. For instance,

$y(x) = a\ln x + \displaystyle\frac{\exp(bx)}{c+x}$

$z(x) = \ln x \cdot \left(1 - \cos x \exp(a^2x) \right)^{r}$

-
What are your $y(x)$ and $z(x)$? –  rm -rf Feb 25 '12 at 8:18
Is this question meant to be on math.stackexchange.com? –  Simon Feb 25 '12 at 8:35
No, I just wanted to know how to take two functions and re-express one in terms of the inverse of the other in Mathematica. I can invert my functions by hand (I just made the two up that are in the question, so I did not try to invert those), but wanted to verify my results by using Mathematica. –  user001 Feb 25 '12 at 8:38
I am aware of how this is done with simple functions (e.g., Solve[Eliminate[{y == x + a, z == x - b}, x], y]), but kept getting error when I did things with transcendental functions. –  user001 Feb 25 '12 at 8:47

To visualize y[z] without having to go through inversion, you can use ParametricPlot:

 Manipulate[
ParametricPlot[{y[x, a, b, c], z[x, a, r]}, {x, 0, 1},
AxesLabel -> {z, y}, AspectRatio -> 1,
PlotRange -> {{-10, 10}, Automatic}],
{{a, 1}, 0, 5, .1}, {{b, 1},  0, 5, .1}, {{c, 1}, 0, 5, .1},
Delimiter, {{r, 1}, .5, 2, .1},
ControlPlacement -> Left]


-

Well, I guess you could try using InverseFunction. However, this will only give explicit algebraic expressions when the function that is to be inverted is fairly simple.

y[x_, a_, b_, c_] := a Log[x] + Exp[b x]/(c + x)
z[x_, a_, r_] := Log[x] (1 - Cos[x] Exp[a^2 x])^r


And you can evaluate and plot $y(x(z))$ where $z \mapsto x(z)$ is the inverse function of $x \mapsto z(x)$

y[InverseFunction[z[#, a, r]&][x], a, b, c]

(* a Log[InverseFunction[z[#1, a, r] &][x]]
+ E^(b InverseFunction[z[#1, a, r]&][x])/
(c + InverseFunction[z[#1, a, r] &][x]) *)

Plot[Evaluate[% /. {a -> 1, b -> 1, c -> 1, r -> 1}], {x, 1, 2}]


Note that InverseFunction does not always behave like you think it might.

-

I am aware of two functions that can eliminate variable algebraically: Eliminate and Solve. They are described in this guide:

These functions work with polynomial equations (or equations that can be reduced to polynomials in some way).

Reduce is more generic, but it doesn't give any means of eliminating $x$ without solving for it first. The syntax to use would be

Reduce[y == f[x] && z == g[x], {y, x}]


It can be guided by giving additional assumption about the variables in the original set of equations/inequalities (for example $x \in \mathbb{R}$ or $x > 0$) or specifying a domain.

That said, a more convenient way to verify the $y = f(z)$ solution you get is to just substitute the original expressions for $y$ and $z$ in terms of $x$ into $y = f(z)$ and verify that the relation hold.

-