#48, Section 6.6: we start by clearing the variables we’re going to create:

Clear[h,d,best,roots];

Here’s the function that we’re going to want to maximize:

Theta[x_]:=ArcTan[(h+d)/x]-ArcTan[d/x];
Together[D[Theta[x],x]]

Let’s give the parameters some sensible values, so that we can actually do some plotting. Assume that the painting is 2 feet high, and that it’s located 4 feet above eye level (keeps it out of arms reach?):

d=2;
h=4;
p1=Plot[Theta[x],{x,0,30},PlotLabel->"Viewing Angle of a Picture on the Wall",AxesLabel->{"Distance","Angle"}]

Here’s the particular derivative in this case:

Together[D[Theta[x],x]]

Let’s create the derivative function, fp (f prime), and then solve for where it’s equal to 0. There are two roots, and I want the positive one, so I select the best location from the roots (the second one is positive):

fp[x_]=D[Theta[x],x];
roots=Solve[fp[x]==0,x]
best=x/.roots[[2]]
Theta[best]

Now I create a graph of the tangent line at the point of optimal viewing (which is just a straight line), and

p2=Plot[Theta[best],{x,0,30}];

then we’ll plot both Theta and the tangent line together on the same graph:

Show[{p1,p2}]