Chain Rule
Calculus I
Andy Long

I created this file to attempt to help students understand the chain rule, by checking out some examples.

In these examples, I compare f, g, and the compositions f(g(x)) and g(f(x)). In each case can you see which is which? 
Then I graph each function in its own plane, so hopefully you can see how the composition falls out of each of f and g operating on each other.

g[x_]:=x^2
f[x_]:=Sin[x]
(* 
g[x_]:=1/x
f[x_]:=Cos[x]
*)
fcompg[x_]:=f[g[x]]
gcompf[x_]:=g[f[x]]
fcompg[x]
gcompf[x]
Plot[{g[x],f[x],fcompg[x]},{x,0,2Pi},PlotRange->{-1,5},PlotLabel->"f(g(x))",PlotLabels->Automatic]
(* and how does that compare with g[f[x]] -- if we change the order of the composition? *)
Plot[{g[x],f[x],gcompf[x]},{x,0,2Pi+1},PlotRange->{-1,5},PlotLabel->"g(f(x))",PlotLabels->Automatic]

Now have a look at their derivatives (compute by hand first, to see if you get the right answer). Why do I plot the three functions that I do?

fcompg'[x]
gcompf'[x]
Plot[{g'[x],f'[g[x]],fcompg'[x]},{x,0,2Pi},PlotRange->{-10,10},PlotLabel->"f'(g(x))",PlotLabels->Automatic]
(* and how does that compare with g[f[x]] -- if we change the order of the composition? *)
Plot[{f'[x],g'[f[x]],gcompf'[x]},{x,0,2Pi+1},PlotRange->{-4,4},PlotLabel->"g'(f(x))",PlotLabels->Automatic]