Linear approximation and tangents

Ivan Cnop
Vrije universiteit Brussel
icnop@vub.ac.be

Pointwise derivative

Scan tangent lines

f[x_]:=Cos[x];
a = -2;
b = 5;

Plot[{f[x],f'[x]},{x, a, b}
,PlotStyle -> {Hue[0.4], Hue[0.8]},
	AspectRatio -> Automatic]

b =. ;
Do[Plot[{f[x],f'[x],f[b] + f'[b] (x - b)},{x, a, b}
,PlotStyle -> {Hue[0  .45], Hue[0.  8], Hue[0.  8]}
		,PlotRange -> {{a, 5}, {-1.5, 1.5}}
	,AspectRatio -> Automatic]
,{b, 0, 5, 0.2}]

f'[x]

Linear approximation of a  function

Example

Clear[f];
f[x_] :=  (Cos[2 x])^2

Plot[f[x], {x, 0, 4}]

factor 2 zooms at a point

h = Table[2^-j, {j, -1, 10}]

zooms[f_, a_, n_]:=
	Do[Plot[{f[x],f[a] + f'[a] (x - a)}
		,{x, a - 2^-j, a + 2^-j}
,PlotStyle -> {Hue[0  .45], Hue[0.  8]}
			,PlotRange -> {{a - 2^-j, 
                      a + 2^-j}, {f[a] - 2^-j, f[a] + 2^-j}}
	,AspectRatio -> Automatic
					,AxesOrigin -> {a, f[a]}
		]
	,{j, 0, n}]

zooms[f,2.6,8]

Global derivatives

convergence

Clear[f];
f[x_]:=Cos[x];
a = -2;
b = 5;

Plot[{f[x],(f[x + 0.5] - f[x])/ .5},{x, a, b}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},
	AspectRatio -> Automatic
	]

animation

h =. ;
Do[Plot[{f'[x],(f[x + h] - f[x])/h},{x, a, b}
,PlotStyle -> {Hue[0  .8], Hue[0.6]}
		,PlotRange -> {{a, 5}, {-1.5, 1.5}}
	,AspectRatio -> Automatic]
,{h, 2.5, 0.1, -0.2}]

for smaller   h  we again use a factor  2 :

h = Table[2^-j, {j, -1, 10}]

Do[Plot[{f'[x],(f[x + 2^-j] - f[x])/2^-j},{x, a, b}
,PlotStyle -> {Hue[0  .8], Hue[0.6]}
		,PlotRange -> {{a, 5}, {-1.5, 1.5}}
	,AspectRatio -> Automatic]
,{j, -1, 10}]

Exercise:

Repeat this animation for functions   x^3,  1/x,  sin x / x ,  ...   and draw conclusions

Clear[f];
f[x_]:=1/x;
a = -4;
b = 4;

h = Table[2^-j, {j, -1, 10}]

Do[Plot[{f'[x],(f[x + 2^-j] - f[x])/2^-j},{x, a, b}
,PlotStyle -> {Hue[0  .8], Hue[0.6]}
		,PlotRange -> {{a, 5}, {-5, 3}}
	,AspectRatio -> Automatic]
,{j, -1, 10}]

The exponential

f[x_]=(2^x)

Plot[{f[x],f'[x]},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	]

f[x_]=(3^x)

Plot[{f[x],f'[x]},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	]

f[x_]=(2.6^x)

Plot[{f[x],f'[x]},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	]

f[x_]=(2.8^x)

Plot[{f[x],f'[x]},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	]

f[x_]=(E^x)

Plot[{f[x],f'[x]},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	]

Now they coincide!

Overview

Do[Plot[{(a^x),D[(a^u),u]/.u -> x},{x, -1, 5}
,PlotStyle -> {Hue[0  .45], Hue[0.6]},PlotRange -> {-1, 200}
	],{a, 2.2, 3.1,  .05}]