# Plotting difference between a function and its inverse function

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.

• 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. Mar 2, 2015 at 18:39

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]"}}]]


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


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

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.