5
$\begingroup$

If $ f(x)=x+6, h(x) = 6x-2$ and $g\circ f = h$, how can I solve for $g(x)$? I know how to do it on paper, but I wonder if Mathematica can do it in a general way. This doesn't work:

f[x_] := x + 6;
h[x_] := 6 x - 2;
Solve[ (g @* f )[x] == h[x], g]
$\endgroup$
2
  • 2
    $\begingroup$ Unfortunately I think mathematica can't solve for functions per se...however, you could possibly try to use InverseFunction in some way to express $h \circ f^{-1}$, or do something clever by somehow turning this into a differential equation for g. That would be cool. Of course both of these approaches have restrictions, and I'd be happy to see a more general approach. $\endgroup$
    – thorimur
    Commented Jul 3, 2022 at 0:32
  • 1
    $\begingroup$ Formally: Composition[Function[x, 6 x - 2], InverseFunction[Function[x, x + 6]]][x] $\endgroup$ Commented Jul 3, 2022 at 17:20

1 Answer 1

13
$\begingroup$

Solve basically works on the level of symbolic algebra, so break down the composition in terms of substitution:

f[x_] := x + 6;
h[x_] := 6 x - 2;

g[u_] = g[u] /. First@Solve[{g[u] == h[x], u == f[x]}, g[u], {x}]
(*  2 (-19 + 3 u)  *)

ClearAll[g];
g[f[x]] == h[x] // Simplify
(*  True  *)

Restriction: As @thorimur's comment implies, f must be invertible; further Mathematica has to be able to somehow solve for the inverse. Note in the above Solve command, f does not actually appear itself, just its value, so that solving for the inverse is merely a simple algebra problem. Yet, Mathematica can use InverseFunction:

Clear[f, g]

g[u_] = g[u] /. First@Solve[{g[u] == h[x], u == f[x]}, g[u], {x}]

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

$\endgroup$

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.