(* MeanValuePlot *) (* Author: Christopher Moretti *) (* Version: 1.0 *) (* MeanValuePlot[fun,{x,a,b}] creates a graphical illustration of the Mean Value Theorem for the function fun on the interval x=a to x=b. The function is plotted in black, the secant line whose slope is the average rate of change is in red, and the parallel tangent lines are in blue.*) MeanValuePlot[fun_,xlist_]:= Block[{x,a,b,l1,l2,tot,av,i,p,n}, x=xlist[[1]];a=xlist[[2]];b=xlist[[3]]; av=( (fun/. x->b)-(fun/.x->a))/(b-a); sols= Select[ (x/. Solve[ D[fun,x]==av,x]), #1>a&sols[[i]]),{i,1,Length[sols]}]; l2=PrependTo[l1,av*(x-a)+(fun/. x->a)]; tot=Flatten[{l1,{fun}}];n=Length[tot]; p[1]=Plot[tot[[1]],{x,a,b},PlotStyle->Hue[2],DisplayFunction->Identity]; Do[ p[i]= Plot[ tot[[i]],{x,a,b},DisplayFunction->Identity,PlotStyle->Hue[.7]],{ i,2,n-1}]; p[n]=Plot[fun,{x,a,b},DisplayFunction->Identity]; Show[Table[p[i],{i,1,Length[tot]}],AspectRatio->Automatic, DisplayFunction->$DisplayFunction]; ]; MeanValuePlot::usage= "MeanValuePlot[fun,{x,a,b}] creates a graphical illustration of the Mean Value Theorem for the function fun on the interval x=a to x=b. " (* Example: MeanValuePlot[x^3-3x,{x,-2,2}] *)