# 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
– 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

## 3 Answers

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.

-

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]
````

-

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.

-
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 21, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8918293714523315, "perplexity_flag": "middle"}