Mathematica Lab #2
Michael Pelsmajer, January 2012

Tip: If you forget how to do something, look at last week’s assignment, which has a lot of worked examples.  Or, try using “Help” at the top of the screen.

Once we have mastered limits, we will be able to find the slope of a tangent line by taking the limit of slopes of secant lines.  Today, you will explore this experimentally.
In particular, you will approximate the slope of a tangent line by the slope of a secant line.

First, run the following code.  (It should produce a plot with buttons and slider bars.)

THIS FOLLOWING CODE WAS ADAPTED FROM

"The Tangent Line Problem" from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/TheTangentLineProblem/

Contributed by: Samuel Leung and Michael Largey

Manipulate[
Switch[ω[x],
x^2,
a=0;b=8;c1=1; c2=3.2;d=-.9999;e=2.5;f={0,7};g={-2,35};c=Max[Min[c2,c],c1];h=Max[Min[e,h],d];i={0,-2.5};j={-2,1};k={1,30};l={1,25};m={1,20};n=Text@Style[Row[{"tangent to ",TraditionalForm[y==x^2]," at Q = (",TraditionalForm[c],", ",TraditionalForm[ω[c]],")"}],18],
(Sqrt[x]),
a=0;b=20;c1=1.8; c2=6;d=-1.99999;e=12;f={0,20};g={0,5};c=Max[Min[c2,c],c1];h=Max[Min[e,h],d];i={0,-2.5};j={-1,2};k={7.5,2};l={7.5,1.5};m={7.5,1};n=Text@Style[Row[{"tangent to ",TraditionalForm[y==Sqrt[x]]," at Q = (",TraditionalForm[c],", ",TraditionalForm[ω[c]],")"}],18],
(E^(-x)),
a=-6;b=6;c1=-0.5; c2=0.4;d=-1.25;e=2.4;f={-5,5};g={-2,10};c=Max[Min[c2,c],c1];h=Max[Min[e,h],d];i={1.5,.5};j={-2,-.75};k={.55,8};l={.55,6};m={.55,4};n=Text@Style[Row[{"tangent to ",TraditionalForm[y==Exp[-x]]," at Q = (",TraditionalForm[c],", ",TraditionalForm[ω[c]],")"}],18]];
Show[
Plot[{ω[x],ω'[c](x-c)+ω[c],((ω[c+h]-ω[c])/h)(x-c)+ω[c]},{x,a,b},PlotStyle->{Thick,Red,Brown},PlotLabel->n],
Graphics[{{Thickness->.01,RGBColor[.6,.73,.36],Line[{{c,0},{c+h,0}}]},
PointSize->Large,
Point[{c,ω[c]}],
Text[Style["Q",18],{c,ω[c]},i],
Point[{c+h,ω[c+h]}],
Text[Style["P",18],{c+h,ω[c+h]}, j],
Text[Style[Row[{Style["P"]," = ("<>ToString[c+h]<>", "<>ToString[N[ω[c+h]]]<>")"}],18,Bold],k,{-1,0}],
Text[Style[Row[{Style["h",Italic]," = "<>ToString[h]}],18,Bold,RGBColor[.6,.73,.36]],l,{-1,0}] ,
Text[Style["secant slope = "<>ToString[N[((ω[c+h]-ω[c])/h)]],18,Bold,Brown],m ,{-1,0}],
Text[Style[If[h<0,Style["-h",Italic],Style["h",Italic]],RGBColor[.6,.73,.36],20],{c+1/2h,0},{0,-1}]
}],
PlotRange->{f,g},
ImageSize->{535,400}
],
{{ω,#^2&,"y = "},
{#^2&->x^2,(Sqrt[#])&->(Sqrt[x]),(E^(-#))&->(E^(-x))},SetterBar},
{c2,3,6,ControlType->None},
{c1,-0.5,1.8,ControlType->None},
{{c,c2,"Q"},c1,c2},
{e,3,15,ControlType->None},
{d,-2.25,.00001,ControlType->None},
{{h,e},d,e},
AutorunSequencing->{{4,5}},TrackedSymbols->True
]

Exercise 1

Play with the buttons and sliders to figure out how it works.
Then use it to answer these approximately:

Question 1: Find the slope of the tangent line to the curve y=(x^2) at x = 2 .
Question 2: Find the slope of the tangent line to the curve y=(x^2) at x = 2.5 .
Question 3: Find the slope of the tangent line to the curve y=(Sqrt[x]) at x=2.
Question 4: Find the slope of the tangent line to the curve y=(Sqrt[x]) at x=((5 π)/3).
Question 5: Find the slope of the tangent line to the curve y=(e^(-x)) at x=0.

Exercise 2

For each of these questions, use Mathematica and show your work.

Question 1: Find the slope of the secant line that intersects y=(x^3)-Cos[x] at x=0.8 and x=1.5 .
Question 2: Find the slope of the secant line that intersects y=(x^3)-Cos[x] at x=0.8 and x=0.5 .
Question 3: Find the slope of a secant line that intersects y=(x^3)-Cos[x] at x=0.8 and approximates the slope of the tangent line at x=0.8 .
Question 4: Find the slope of a secant line that intersects y=(x^3)-Cos[x] at x=1.5 and approximates the slope of the tangent line at x=1.5 .

Exercise 3

Mathematica can find the slope of the tangent line directly.  (In this example, I named my function MrFunction, but of course you can use f or g or dog or cat or whatever.)
Here, I find the tangent slope to MrFunction at x=10.

MrFunction[x_] := Sqrt[x-3]

MrFunction'[10]

Use this method to find these tangent slopes exactly:
Question 1: Find the slope of the tangent line to the curve y=(x^2) at x = 2 .
Question 2: Find the slope of the tangent line to the curve y=(x^2) at x = 2.5 .
Question 3: Find the slope of the tangent line to the curve y=(Sqrt[x]) at x=2.
Question 4: Find the slope of the tangent line to the curve y=(Sqrt[x]) at x=((5 π)/3).
Question 5: Find the slope of the tangent line to the curve y=(e^(-x)) at x=0.
Question 6: Find the slope of the tangent line to the curve y=(x^3)-Cos[x] at x=0.8 .
Question 7: Find the slope of the tangent line to the curve y=(x^3)-Cos[x] at x=1.5 .