The Maximum Rectangular Area under Different Curves

f1[X_]:=4-X^2;
f2[X_]:=2-X/2;
f3[X_]:=Sqrt[16-X^2];
f4[X_]:=(4-X)/(1+(X^2));
f5[X_]:=4Cos[X/2];

Manipulate[
Switch[func,f1,If[X>2,X=1];maxX=2,f2,maxX=4,f3,maxX=4,f4,maxX=4,f5,If[X>π,X=1];maxX=π];
funcPlot=Plot[func[X],{X,0,maxX},PlotStyle->{Thickness[0.007],Black},PlotRange->{{0,4},{0,4}},AspectRatio->1(*,PlotLabel->Style[Row[{TraditionalForm[f[x]]," = ",func[X]}],18]*),ImageSize->{300,300}];
areaRect[X_]:=X func[X];
pointOnCurve={X,func[X]};
pointOnAreaCurve=Graphics[{PointSize[Large],RGBColor[.6,.73,.36],Point[{X,areaRect[X]}]}];
rectangle=Graphics[{EdgeForm[Directive[Thick,Blue]],RGBColor[.6,.73,.36],Rectangle[{0,0},pointOnCurve]}];
areaPlot=Plot[areaRect[X],{X,0,maxX},PlotLabel->Style["area of rectangle",18],ImageSize->250];
Text@Pane[Row[{Show[funcPlot,rectangle],Column[{Show[areaPlot,pointOnAreaCurve],"",Style[Row[{Style["x",Italic]," = ",X}],24],Style[Row[{"area = ",areaRect[X]}],24]}]}],ImageSize->{560,300}],
{{func,f1,"f(x)"},{f1->TraditionalForm[4-(x^2)],f2->TraditionalForm[2-x/2],f3->TraditionalForm[(Sqrt[16-(x^2)])],f4->TraditionalForm[(4-x)/((x^2)+1)],f5->TraditionalForm[4Cos[x/2]]},ControlType->PopupMenu},
{{X,1},0,Dynamic[maxX]},
{{maxX,2},ControlType->None},
AutorunSequencing->{1,2},
TrackedSymbols->True,SaveDefinitions->True]

This Demonstration illustrates a common type of max-min problem from a Calculus I course—that of finding the maximum area of a rectangle inscribed in the first quadrant under a given curve. A variety of curves are included.

Contributed by: Marc Brodie (Wheeling Jesuit University)