Lesson 6 of 18

Critical Points

Critical Points

A critical point is where f(x)=0f'(x) = 0 or f(x)f'(x) is undefined. Critical points are candidates for local maxima and minima.

Finding Critical Points Numerically

We use bisection on f(x)f'(x): if f(a)<0f'(a) < 0 and f(b)>0f'(b) > 0 (or vice versa), by the Intermediate Value Theorem there must be a zero of ff' between aa and bb.

while (ba)>tolerance:\text{while } (b - a) > \text{tolerance}: m=a+b2\quad m = \frac{a + b}{2} if f(a) and f(m) have the same sign: a=m\quad \text{if } f'(a) \text{ and } f'(m) \text{ have the same sign: } a = m else: b=m\quad \text{else: } b = m return a+b2\text{return } \frac{a + b}{2}

Classifying Critical Points

Once we find cc where f(c)=0f'(c) = 0:

Second derivativeClassification
f(c)>0f''(c) > 0Local minimum (concave up)
f(c)<0f''(c) < 0Local maximum (concave down)
f(c)=0f''(c) = 0Inconclusive (use first derivative test)

Example

For f(x)=x24x+3f(x) = x^2 - 4x + 3:

  • f(x)=2x4=0f'(x) = 2x - 4 = 0x=2x = 2
  • f(2)=2>0f''(2) = 2 > 0 → local minimum
  • f(2)=48+3=1f(2) = 4 - 8 + 3 = -1 is the minimum value

Global Extrema

On a closed interval [a,b][a, b], the global max/min occurs either at a critical point or at an endpoint. Evaluate ff at all critical points and both endpoints, take the largest/smallest.

Your Task

Implement double critical_point(double (*f)(double), double a, double b, int n, double h) that uses bisection on ff' to find a critical point in [a,b][a, b]. Run nn bisection steps; hh is the step for numerical differentiation.

TCC compiler loading...
Loading...
Click "Run" to execute your code.