---
author: Nathan Carter (ncarter@bentley.edu)
---

This answer assumes you have imported SymPy as follows.


```python
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output
```

Let's create an example function to work with.


```python
var( 'x' )
formula = sqrt( x - 1 ) - x
formula
```




$\displaystyle - x + \sqrt{x - 1}$



Critical numbers come in two kinds.  First, where is the derivative zero?
Second, where is the derivative undefined but the function is defined?

Let's begin by finding where the derivative is zero.  We'll use the same
techniques introduced in how to write symbolic equations and
how to solve symbolic equations.


```python
derivative = diff( formula )
derivative
```




$\displaystyle -1 + \frac{1}{2 \sqrt{x - 1}}$




```python
solve( Eq( derivative, 0 ) )
```




$\displaystyle \left[ \frac{5}{4}\right]$



So one critical number, where the derivative is zero, is $x=\frac54$.

Now where is the derivative defined but the function undefined?
We compute the domain of both functions and subtract them, using the techniques
from how to compute the domain of a function.


```python
from sympy.calculus.util import continuous_domain
f_domain = continuous_domain( formula, x, S.Reals )
deriv_domain = continuous_domain( derivative, x, S.Reals )
Complement( f_domain, deriv_domain )
```




$\displaystyle \left\{1\right\}$



So another critical number, where the function is defined but the derivative is not,
is $x=1$.

Thus the full set of critical numbers for this function is $\left\{1,\frac54\right\}$.

fca0ce303129986fbdee75b3665db1d3ef8e42fa
ipynb
Jupyter Notebook
database/tasks/How to find the critical numbers of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to find the critical numbers of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to find the critical numbers of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
2021-07-18T19:01:29.000Z
2022-03-29T06:47:11.000Z
Qwen/Qwen-72B
1. YES
2. YES