1
$\begingroup$

I'm trying to define a function f(x) such that 1/f(x) = 1/R - A/B. I know that I can just work the RHS out so that f(x) = C/D and then define it like that, but I was wondering if there was a way to directly define the function without simplification. In some cases it may be very difficult to simplify it to get a f(x) = form.

$\endgroup$
6
  • 2
    $\begingroup$ Your code-formatted bits are not Mathematica code -- just to confirm, you want to do this is in the software Mathematica? $\endgroup$
    – Michael E2
    Apr 22, 2021 at 0:59
  • $\begingroup$ f[x_]:=1/(1/R - A/B) ? $\endgroup$
    – murray
    Apr 22, 2021 at 14:27
  • $\begingroup$ @MichaelE2 yes its in Mathematica $\endgroup$
    – sarat.kant
    Apr 22, 2021 at 15:42
  • $\begingroup$ @murray yes like I mentioned, this might not be simple to do in other situations so I wanted a way to define it directly $\endgroup$
    – sarat.kant
    Apr 22, 2021 at 15:42
  • $\begingroup$ Are you looking for a function inverse or a reciprocal? $\endgroup$ Apr 23, 2021 at 0:18

1 Answer 1

2
$\begingroup$

You can use InverseFunction for this so long as your LHS is of the form g[f[x]]:

g[y_] := 1/y;
f[x_] := InverseFunction[g] @ (1/R[x] - A[x]/B[x])
f[x]

If InverseFunction[g] can be computed symbolically, then it might be more efficient to use immediate assignment for f instead (i.e, f[x_] = ) so that the inverse does not have to be re-computed each time you call f, but you'll need to be careful that x is not already defined then. You can use Block or Module to ensure this, if necessary:

Block[{x},
 f[x_] = InverseFunction[g] @ (1/R[x] - A[x]/B[x])
]

If you don't like defining an axillary function g, you can use pure functions instead (e.g., InverseFunction[1/# &]).

$\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.