2
$\begingroup$

I would like to plot the difference a function and its inverse function.

(1/27)*(x^4-6x^3+12x^2+19x) (* where 0<x<5 *)

I tried the following:

f = (1/27)*(#^4-6#^3+12#^2+19#) &;
g = InverseFunction[f]
Plot[f-g, {x, 0, 5}]

But it seems not work well.

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Mar 2, 2015 at 18:39

2 Answers 2

4
$\begingroup$
ClearAll[f, g]
f = ConditionalExpression[(1/27)*(#^4 - 6 #^3 + 12 #^2 + 19 #),  0 <= # <= 5] &;
g = InverseFunction[f];

Grid[Partition[#, 2] &[Plot[#, {x, 0, #2}, PlotLabel -> #3, ImageSize -> 300] & @@@ 
    {{f[x], 5, "f[x]"}, {g[x], 10, "g[x]"},
     {{f[x], g[x]}, 5,  "{f[x], g[x]}"}, {f[x] - g[x], 5, "f[x]- g[x]"}}]]

enter image description here

Update: You can also use ParametricPlot to plot f, g and f-g:

ParametricPlot[{{x, f[x]}, {f[x], x}, {x, f[x] - g[x]}}, {x, -1, 5},
 BaseStyle -> Thick, Frame -> True, PlotStyle -> (c = {Red, Blue, Green}), 
 PlotLegends -> LineLegend[c, {"f[x]", "g[x]", "f[x]-g[x]"}, BaseStyle -> Thick]]

enter image description here

$\endgroup$
2
  • $\begingroup$ To plot f[x]-g[x] correctly, the third funcion of the ParameterPlot f[x]-x should be f[x]-g[x]? $\endgroup$
    – MS.Kim
    Commented Mar 3, 2015 at 3:50
  • $\begingroup$ @MS.Kim, you are right. Just updated the post with the correction. $\endgroup$
    – kglr
    Commented Mar 3, 2015 at 8:10
1
$\begingroup$

Illustrating the problem with a simple example:

f = #^2 &;
g = InverseFunction[f];

InverseFunction::ifun: Inverse functions are being used. Values may be lost for multivalued inverses.

g[f[3]]

-3

As the message says, there may be multiple solutions. Only one is returned.

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