(*Video 1: Concave up/down *)

f[x_]:=30+6 x-15 (x^2)+3 (x^3)+(x^4);
Manipulate[Grid[{{Row[{"Value of second derivative is f''[x0]=",f''[x0]}]},{Plot[{f[x],f'[x0](x-x0)+f[x0]},{x,-10,5},PlotStyle->{Normal,Gray},PlotRange->{-200,200},ImageSize->500]}},Spacings->{1,1},Frame->All],{{x0,-3},-10,5}]

(* f''>0 / Tangent line locally below graph  --- function is concave up*)
(* f''<0 / Tangent line locally above graph  --- function is concave down*)
(* Points x0 where concavity changes from up to down or down to up are INFLECTION POINTS
*)

Plot[{f[x],f'[x],f''[x]},{x,-10,5}]

f''[x]

Factor[f''[x]]

Reduce[f''[x]>0](*With Mathematica we can use Reduce*)
Reduce[f''[x]<0]

(*Inflection points:*)
Solve[f''[x]==0,x]

concaveup=Show[Plot[f[x],{x,-10,-5/2},PlotRange->{{-10,5},{-200,200}},PlotStyle->Blue],
Plot[f[x],{x,1,5},PlotRange->{{-10,5},{-200,200}},PlotStyle->Blue]]

concavedown=Plot[f[x],{x,-5/2,1},PlotRange->{{-5,5},{-200,200}},PlotStyle->Red]

Show[concaveup,concavedown]

(*Video 2: Second derivative test*)

(* If x=x0 is a critical point of f[x], that is f'[x0]==0, and,
 f''[x0]>0 then x=x0 is a local minimum,
 f''[x0]<0 then x=x0 is a local maximum.
However: if f''[x0]==0, then test is inconclusive (anything can happen!)
*)

(*Find the critical points and classify them into local min, local max, or neither:*)
f[x_]:=3x^5-5x^3+3

Plot[f[x],{x,-2,2}]

f'[x]

Solve[f'[x]==0,x]

(*There are 3 critical points: x=-1, x=0, and x=1 *)

f''[x]/.{x->-1}

(* x=-1 is a local maximum!*)

f''[x]/.{x->1}

(* x=1 is a local minimum!*)

f''[x]/.{x->0}

(*test is inconclusive... *)

Plot[f[x],{x,-1/2,1/2}]

Manipulate[Grid[{{Row[{"Value of second derivative is f''[x0]=",f''[x0]}]},{Plot[{f[x],f'[x0](x-x0)+f[x0]},{x,-2,2},PlotStyle->{Normal,Gray},PlotRange->{-5,5},ImageSize->500]}},Spacings->{1,1},Frame->All],{{x0,0},-2,2}]

Plot[f'[x],{x,-1/2,1/2}]

(* Tangent line has negative slope both before and after x=0, so x=0 is not a local min, nor a local max. *)

f''[x]

Plot[{f[x],f'[x],f''[x]},{x,-3/2,3/2}]

Solve[f''[x]==0,x]

(*All of these 3 points are inflection points*)

Reduce[f''[x]>0,x](*concave up!*)

Reduce[f''[x]<0,x](*concave down!*)

concaveup=Show[Plot[f[x],{x,-(1/(Sqrt[2])),0},PlotRange->{{-3/2,3/2},{-5,5}},PlotStyle->Blue],
Plot[f[x],{x,(1/(Sqrt[2])),3/2},PlotRange->{{-3/2,3/2},{-5,5}},PlotStyle->Blue]]

concavedown=Show[Plot[f[x],{x,-3/2,-(1/(Sqrt[2]))},PlotRange->{{-3/2,3/2},{-5,5}},PlotStyle->Red],
Plot[f[x],{x,0,(1/(Sqrt[2]))},PlotRange->{{-3/2,3/2},{-5,5}},PlotStyle->Red]]

Show[concavedown,concaveup]