Exercise 4. Single variable calculus (Contd.)

Exercise 1. Using the definition of derivative, calculate f ’(3), where f(x)=((sin π x)/x). Compare with the difference quotients for Δx=1, 0.1, 0.01, 0.001, 0.0001. Visualize the results in a table.

f[x_]:=((Sin[π x])/x)
Limit[((f[3+Δx]-f[3])/(Δx)),Δx->0]//N
diffQuotients=Table[((f[3+Δx]-f[3])/(Δx)),{Δx,{1,0.1,0.01,0.001,0.0001}}];
Grid[{{"Δx",1,0.1,0.01,0.001,0.0001},Prepend[diffQuotients,"Difference Quotients"]},Frame->All]

Exercise 2. Find the local extrema of the functions f(x)=(x^3)-9x+5 and g(x)=((sin π x)/x), 0≤x≤3.

f[x_]:=(x^3)-9x+5
NSolve[f'[x]==0,x]

f[{-1.73205,1.73205}]
Plot[f[x],{x,-5,5}]

Thus, the function has a local maximum 15.3925  at x = -1.73205 and a local mimumum - 5.3923 at x = 1.73205

Exercise 3. Using a Taylor expansion about x=0, estimate (∫_0^1)(e^x)dx. Compare with the exact value.

f[x_]:=E^x
taylorPoly[f_,n_,x0_]:=(∑_(i=0)^n)((D[f[x],{x,i}]/.{x->x0})/(i!))(((x-x0))^i)
Manipulate[
p[x_]=taylorPoly[f,n,0];
Plot[{(E^x),p[x]},{x,0,1}],{n,1,10,1}]

Graphically, we can see that the 5th order Taylor expansion is “close” to f(x) in the given interval. Thus, we shall use to estimate the value of the integral.

p[x_]=taylorPoly[f,5,0];
Print["Approximate value, using the Taylor expansion:"]
appr=NIntegrate[p[x],{x,0,1}]
Print["Exact value:"]
exact=NIntegrate[E^x,{x,0,1}]
Print["Absolute error:", exact-appr]

Exercise 4. Compute ∫(1/(1-(x^3)))dx, ∫(x^n)dx, ∫(Sqrt[(t^4)+2(t^2)+1])dt

Integrate[(1/(1-(x^3))),x]//Simplify
Integrate[(x^n),x]//Simplify
Integrate[(Sqrt[(t^4)+2(t^2)+1]),t]//Simplify

Remark 1: The second result is not defined for n=-1. Mathematica returns the result that is correct in “almost” all cases.

Remark 2: For the last integral it holds true that ∫(Sqrt[(t^4)+2(t^2)+1])dt=∫(Sqrt[((((t^2)+1))^2)])dt=((t^3)/3)+t. Mathematica by default assumes complex variables. This is the reason it does not simplify the integral. We can modify the code as follows.

Integrate[(Sqrt[(t^4)+2(t^2)+1]),t, Assumptions->{t∈Reals}]//Simplify