source: http://calculuswithjulia.github.io/precalc/inversefunctions.html
using CalculusWithJulia
gr()
## Plots.GRBackend()
f(x)=2^x
## f (generic function with 1 method)
plot(f,0,4)
plot!([2, 2, 0], [0, f(2), f(2)])
If we view a function as a composition of many actions, then we find the inverse by composing the inverse of these actions in reverse order.
The graph of \(f(x)\) is a representation of all values \((x, y)\) where \(y=f(x)\). As the inverse flips around the role of \(x\) and \(y\) we have:
If \((x,y)\) is a point on the graph of \(f(x)\), then \((y,x)\) will be a point on the graph of \(f^{-1}(x)\)
f(x) = 2^x
## f (generic function with 1 method)
xs = range(0, 2, length=50)
## 0.0:0.04081632653061224:2.0
ys=f.(xs)
## 50-element Array{Float64,1}:
## 1.0
## 1.0286957334762774
## 1.0582149120722961
## 1.088581165149745
## 1.1198188001321776
## 1.1519528219624953
## 1.1850089531187766
## 1.2190136542044754
## 1.25399414512947
## 1.2899784268989174
## â‹®
## 3.1898075565472563
## 3.2813414240305514
## 3.3755019229792005
## 3.4723644265096736
## 3.572006470625302
## 3.6745078162819036
## 3.7799505132344264
## 3.8884189657157195
## 4.0
plot(xs, ys, color=:blue)
plot!(ys, xs, color=:red)
f(x)=cbrt(x)
## f (generic function with 1 method)
xs=range(-2,2,length=150)
## -2.0:0.026845637583892617:2.0
ys=f.(xs)
## 150-element Array{Float64,1}:
## -1.2599210498948732
## -1.2542584069509184
## -1.2485441663946044
## -1.2427771365281286
## -1.2369560809963789
## -1.2310797164530598
## -1.2251467100693285
## -1.2191556768718537
## -1.2131051768958987
## -1.2069937121375889
## â‹®
## 1.2131051768958987
## 1.2191556768718537
## 1.2251467100693285
## 1.2310797164530598
## 1.2369560809963789
## 1.2427771365281286
## 1.2485441663946044
## 1.2542584069509184
## 1.2599210498948732
plot(xs, ys, color=:blue, aspect_ratio=:equal, legend=false)
plot!(ys, xs, color=:red)
plot!(identity, color=:green, linestyle=:dash)
x, y = 1/2, f(1/2)
## (0.5, 0.7937005259840998)
plot!([x,y], [y,x], color=:green, linestyle=:dot)
f(x)=sqrt(x)
## f (generic function with 1 method)
c=2
## 2
tl(x)=f(c) + 1/(2*sqrt(2)) * (x -c)
## tl (generic function with 1 method)
xs = range(0, 3, length=150)
## 0.0:0.020134228187919462:3.0
ys=f.(xs)
## 150-element Array{Float64,1}:
## 0.0
## 0.14189513095212064
## 0.20067001862719533
## 0.24576957615571215
## 0.2837902619042413
## 0.3172871584851762
## 0.34757066781809537
## 0.3754192287502549
## 0.40134003725439066
## 0.42568539285636187
## â‹®
## 1.6849113254105226
## 1.6908756319388378
## 1.6968189741019764
## 1.7027415714254475
## 1.7086436396300788
## 1.7145253907236957
## 1.7203870330899849
## 1.7262287715746372
## 1.7320508075688772
zs=tl.(xs)
## 150-element Array{Float64,1}:
## 0.7071067811865477
## 0.7142253058293653
## 0.7213438304721829
## 0.7284623551150005
## 0.735580879757818
## 0.7426994044006356
## 0.7498179290434532
## 0.7569364536862708
## 0.7640549783290884
## 0.771173502971906
## â‹®
## 1.7108187558238281
## 1.7179372804666457
## 1.7250558051094633
## 1.732174329752281
## 1.7392928543950985
## 1.746411379037916
## 1.7535299036807337
## 1.7606484283235513
## 1.7677669529663689
plot(xs, ys, color=:blue, legend=false)
plot!(xs, zs, color=:blue) # the tangent line
plot!(ys, xs, color=:red) # the inverse function
plot!(zs, xs, color=:red) # inverse of tangent line
If the graph of \(f(x)\) has a tangent line at \((c, f(c))\) with slope \(m\), then the graph of \(f^{-1}(x)\) will have a tangent line at \((f(c), c)\) with slope \(1/m\).