Calculus I:  Mathematica Practice 1

Syntax Checks

Clear[f,g,h]

The following Mathematica commands have syntax errors. Fix the errors so the commands will work.

Problem 1

plot[x^2,(x,-2,2)]

Problem 2

h[x]=Exp[x]
h[1]

Problem 3

a=0.1
g[x]=(3x-4)/(ax)
Plot[g[x],{x,1,3}]

Problem 4

Solve[3x^2-4x=2,x]

Problem 5

f[x_]=e^{-3x}
Plot[f[x],{x,-2,2}]

Problem 6

f[t_]=Log[t^2]
Solve[f[x]==3,t]

Example Based on 1.6 Inverse Functions

Find an explicit formula for the inverse function of f(x)=(Sqrt[(x^2)+2x]), x>0. Then graph y=f(x), y=(f^(-1))(x), and y=x on the same screen. Are the graphs of y=f(x) and y=(f^(-1))(x) reflections about the line y=x? Using Mathematica, attempt to verify the cancellation equations f((f^(-1))(x))=x and (f^(-1))(f(x))=x. What happens?

Barry's Solution

Calculate the inverse (this part is done by hand on paper):

y=(Sqrt[(x^2)+2x])
x=(Sqrt[(y^2)+2y]) (interchange x and y)
(x^2)=((((Sqrt[(y^2)+2y])))^2)=(y^2)+2y (solve for y)
(y^2)+2y-(x^2)=0

Now, use the quadratic formula to solve for y, or use Mathematica's Solve:

Solve[y^2+2y-x^2==0,y]

Which one do we use? Since y=f(x)>0, we have to choose the one that gives us y>0, which is the second solution. Therefore, we have

f[x_]=Sqrt[x^2+2x]
finv[x_]=-1+(Sqrt[1+(x^2)])

Plot[{f[x],x,finv[x]},{x,0,2},AspectRatio->1,PlotStyle->{Blue,Red,Green}]

Check the cancellation equations:

f[finv[x]]

Simplify[%]

finv[f[x]]

Simplify[%]

These do equal x, but only if x>0, which Mathematica doesn't know.

Example Based on 2.2 The Limit of a Function

(a) Evaluate h(x)=(tan x - x)/(x^3)for x=1,0.5,0.1,0.05,0.01, and 0.005.

(b) Guess the value of (lim_(x->0)) h(x).

(c) Evaluate h(x) for successively smaller values of x until you finally reach 0 for h(x). Are you still confident that your guess in part (b) is correct? Explain why you eventually obtained 0 values.

(d) Graph h(x) in a viewing ractangle [-1,1] by [0,1]. Then zoom in toward where the graph crosses the y-axis in order to
estimate (lim_(x->0)) h(x). Continue to zoom in until you observe distortions in the graph of h(x). Compare with the results of part (c).

Barry's Solution

First, we define the function:

h[x_]=(Tan[x]-x)/x^3

Now, we evaluate it at a number of values for x:

h[1.]

h[0.5]

h[0.1]

h[0.05]

h[0.01]

h[0.005]

I guess that the limit of h(x) as x->0 is 1/3. Let's try to check that by taking a very small value for x:

h[0.00000003]
h[0.000000003]

I am no longer confident in my guess! Numerical roundoff error has entered our problem. The numerator and denominator are both very small for x~0, and this leads to our incorrect estimate of  (lim_(x->0)) h(x). Let's examine this in more detail:

num[x_]=Tan[x]-x
den[x_]=x^3

num[0.000000003]
den[0.000000003]

We can see the same numerical difficulties more readily in a series of sketches, in which we "zoom in" around x=0:

Plot[h[x],{x,-1,1},PlotRange->{{-1,1},{0,1}}]

Plot[h[x],{x,-0.1,0.1}]

Plot[h[x],{x,-0.01,0.01}]

Plot[h[x],{x,-0.001,0.001}]

Plot[h[x],{x,-0.00001,0.00001}]

Example Based on 2.3 Calculating Limits

Graph the functions y=-(x^2), y = (x^2) cos (20 π x), y=(x^2)  on the same screen. This illustrates that you would be able to use the Squeeze Theorem to show (lim_(x->0)) (x^2) cos (20 π x) = 0 .

Barry's Solution

First, we define the functions:

f[x_]=-x^2
g[x_]=x^2 Cos[20Pi*x]
h[x_]=x^2
Plot[{f[x],g[x],h[x]},{x,-1,1},PlotStyle->{Red,Green,Blue}]