Chapter 3 -- Second Part   (begins with page 85)

3.5  Optimization (page 85)

Local Extrema

Example 3.5.1  (on page 86)

Clear[f];  f[x_] = x^5 - 4x^4 - x^3 +16x^2-12x

Plot[f[x], {x,-2.2,3.3}]

critnos = x /. NSolve[ f'[x]==0, x]

f[critnos]

Plot[ x^3, {x, -1, 1}, PlotRange->All]

The Second Derivative Test

Example 3.5.2a        (on page 87)

Clear[f];  f[x_] = 1 - 5x + 44x^2 -152x^3 +256x^4 - 208x^5 + 64x^6

f'[x]

Clear[critnos];   critnos = x /. Solve[f'[x]==0, x]

f''[x]

f''[critnos] //N

?Part

critnos[[4]]

f[  critnos[[4]]  ]  //N

critnos[[5]]

f[ critnos[[5]]  ] //N

Factor[ f''[x] ]                                            (*  1/2 is a root of multiplicity 2  *)

f[.5]

Plot[ f[x], {x, -.2, 1.3}]

Example 3.5.2b    (page 88)

Clear[f];  f[x_] = 1 + 5x - 34x^2 +  84x^3 - 88x^4 +32x^5

f'[x]

Clear[ critnos];  critnos = x /. Solve[ f'[x] == 0, x]

f''[x]

f''[ critnos ] //N

critnos[[3]]

f[ critnos[[3]] ] //N

critnos[[4]]

f[ critnos[[4]] ] //N

Factor[ f''[x] ]                                        (*   1/2 is a root of multiplicity 1  *)

Plot[ f[x], {x, -.15, 1.3}]

Using  FindMinimum     (page 89)

The two local minima of the function

Clear[f];  f[x_] = x^5 - 4x^4 - x^3 +16x^2-12x

in Example 3.5.1 are found as follows.

FindMinimum[ f[x], {x, .5}]

FindMinimum[ f[x], {x, 2.5}]

For the same function,

FindMinimum[ -f[x], {x, -1}]

FindMinimum[ -f[x], {x, 1.5}]

Of course, the corresponding local maxima of f(x) are approximately  30.1602  and  1.97771 .

FindMaximum[ f[x], {x, -1}]

FindMaximum[ f[x], {x, 1.5}]

Other Kinds of Critical Numbers    (Page 89)

Clear[f]

(x^(1/3))  //FullForm

x^(1/3)  //FullForm

?If

f[x_] := If[ -2 <x < 2, - (2 - Abs[x])^(1/3), (Abs[x]-2 )^(1/3) ]

Plot[ f[x], {x, -6, 6}]

?Which

Note that f(x) is equal to the function g(x) defined as follows.

g[x_] :=  Which[ -2<x<2, - (2 - Abs[x])^(1/3), x<=-2 || x≥2,  (Abs[x]-2 )^(1/3)]

Plot[g[x],{x,-6,6}]

FindMinimum[ f[x], {x, 1}]

FindMinimum[ f[x], {x, -1,1}]

Absolute Extrema on Closed Intervals

Example 3.5.4    (on page 90)

Clear[f];  f[x_] = x^3-x

Plot[ f[x], {x, -1, 3/2}, PlotRange->All]

sol = Solve[ f'[x]==0, x]

{x,f[x]} /. sol

Clear[ f,  critnos ];  f[x_] = (3x+1)(2x-1)(3x-5)(x-3)(2x-9)(x-5)

Expand[ f[x] ]

critnos = x /. NSolve[f'[x]==0, x]

An explanation of the notation in the following input statement follows this exercise.

in04[x_] := (0 < x < 4)

{in04[2.37], in04[5.1]}

?Select

critnos = Select[ critnos, in04]

candidates = Union[critnos, {0, 4}]

vals = f[candidates]

Max[vals]

Min[vals]

Plot[ f[x], {x, 0, 4}]

Exercises     (on page 92)

Exercise 1.

?NSolve

?FindMinimum

Exercises   (on page 92)

Provided that you have saved anything that you may wish to save,  you can start a new kernel to avoid earlier definitions 
(rather than bother trying to remember that to which  Clear  should be applied).  You can click the menu item  Evaluation  and then click  Quit Kernel.  Or, you can evaluate the following input statement.

Quit[]

Exercise 3.   (on page 92)

Clear[f]

f[x_] = x^3*Exp[-x^2]                                    (*  or   f[x_] = x^3*E^(-x^2)   *)

f'[x] //Factor

Plot[ f[x], {x,-5,5}, PlotRange->All]

sol =  NSolve[ f'[x]/Exp[-x^2] == 0, x]

?Part

sol[[{1,2,4}]]

Thus, the critical numbers are given by

critnos = x /. sol[[{1,2,4}]]

and the critical points are given by

{x, f[x]} /. sol[[{1,2,4}]]

Exercise 4.    (on page 92)

Quit[]

g[x_] := - (-x)^(1/3)*(x-1)

h[x_] := x^(1/3)*(x-1)

f[x_] := Which[ x<0, g[x], x==0,0, x> 0, h[x]]

Plot[f[x],{x,-1,2}]

Solve[g'[x]==0,x]   (* and restrict x to be negative  *)

sol = Solve[ h'[x]==0,x]  (* and restrict x to be positive  *)

So, the critical numbers are   0  and  1/4 ;  and the critical points are

{ {0,f[0]}, {1/4,f[1/4]} }

Thus, there is only one local extreme value and it is a local minimum at x = 1/4.

3.6  Applied Optimization Problems      (on page 93)

Example 3.6.1  (on page 93)

costxy[x_,y_] = .5(2x^2+2x*y) + .35x*y +.1(6x+2y) + .05(2(2x+2y)) //Simplify

cost[x_] = costxy[x, 20/x^2] //Simplify

Plot[ cost[x], {x,0,10}, PlotRange->{0,100}]

FindRoot[ cost'[x], {x,2}]

FindMinimum[ cost[x], {x,2}]

20/2.43386^2   (*feet*)

Example 3.6.2   (on page 94)

volrh[r_,h_] = (Pi/3)r^2*h

hrEqn = (h - rho)/rho == Sqrt[h^2+r^2]/r

sol = Solve[hrEqn, h] // Flatten

?Part

sol[[2]]

h[r_] = h /. sol[[2]]

vol[r_] = volrh[r, h[r]]

vol'[r]

-((4 π (r^5) rho)/(3 ((((r^2)-(rho^2)))^2)))+((8 π (r^3) rho)/(3 ((r^2)-(rho^2))))  //Factor

Solve[ vol'[r] == 0, r]

vol''[Sqrt[2]*rho]

h[ Sqrt[2]*rho]

vol[Sqrt[2]rho]

Plot[ vol[r] /. rho->1, {r,1,4}, PlotRange->{0,40}]

Exercises     (page 96)

3.7  Antiderivatives   (page 97)

Integrate[ 3x^2, x]

Integrate[ Cos[x], x]

Integrate[ x + x^3, x]

Integrate[ 1/(x^2+3), x]

Integrate[ x/(x^2+x-2), x]

Integrate[ x*Cos[x], x]

Integrate[ x^2*Exp[-x], x]

Clear[f];   D[ Integrate[ f[x], x], x]

Integrate[ f'[x], x]

Integrate[ Exp[-x^2], x]

Integrate[ Sin[x^2], x]

Differential Equations and Initial Values   (page 99)

Example 4.1.1   (page 99)

antiD[t_] = Integrate[ t^2*Sin[t], t]+C

sol = Solve[ antiD[0]==1/2,C]

answer[t_] = (antiD[t] /. sol)[[1]]

Example 4.1.2

antiD1[t_] = Integrate[ t*Exp[-t], t] +C1

sol1 = Solve[ antiD1[0]==1,C1]

yprime[t_] = (antiD1[t]  /. sol1)[[1]]

antiD2[t_] = Integrate[ yprime[t], t] +C2

sol2 = Solve[antiD2[0]==-1,C2]

y[t_] = ( antiD2[t] /. sol2 )[[1]]

Plot[ y[t], {t,-1,1}]

Exercises   (page 100)

Exercise 1.

Integrate[ x^3-6x+3, x]

Exercise 2.

Integrate[ 5*Sqrt[x], x]

Exercise 4.

Integrate[ Cos[x] - Sin[x], x]

Exercise 6.

Integrate[ Sin[Pi*x], x]

Exercise 8.

Integrate[ (x+3)/(x+1), x]

Apart[  (x+3)/(x+1) ]

Exercise 10.

Integrate[ Cos[x] - Sin[x], x]

Exercise 12.

int =Integrate[ Sin[x]^3, x]

TrigExpand[int]

TrigExpand[ int ] /. Sin[x]^2->1-Cos[x]^2 //Expand

Here, it took some effort to put the answer in the form that we would most readily obtain in Calculus II.

Exercise 14.

Clear[ antiD, antiD1, antiD2, yprime ]

antiD[t_] = Integrate[ t^2 - 4t,t]

y[t_] = antiD[t] - antiD[1] +2

As a check, we note that

{ y'[t], y[1] }

Exercise 15.   (on page 100)

(At  t = 0,  the derivatives are to be interpreted as right-hand derivatives.)

antiD1[t_] = Integrate[ Sqrt[t],t]

yprime[t_] = antiD1[t] -antiD1[0] -1

antiD2[t_] = Integrate[ yprime[t], t ]

y[t_] = antiD2[t] -antiD2[0] + 1

As a check, we note that

{ y''[t], y'[0], y[0] }

For the quiz on the material in pages 85--100 of our textbook 
(the coverage of this notebook during the week of Feb. 3-- Feb. 7), 
be able to write input for MATHEMATICA in connection with:
  1. finding the critical numbers of a given polynomial function;   
  (e.g., Example 3.5.1 on page 85)
  2. finding the values of a given function at its critical numbers,  
  (e.g., Example 3.5.1 on page 85)
  3. the anti-differentiation problems page 100; e.g., have MATHEMATICA compute an antiderivative for f(x) = (1/((x^10)-3(x^8)+2(x^6)+2(x^4)-3(x^2)+1)).