# Nonlinear Models, Polynomial Functions

```
import matplotlib.pyplot as plt
import numpy as np
import math
```

Linear and quadratic functions are part of a general class of **polynomial functions**. A polynomial function is given by

\[f(x) = a_nx^n + a_{n-1}x^{n-1}, + \dots + a_2x^2 + a_1x^1 + a_0\]

where \(n\) is a nonnegative integer and \(a_n, a_{n-1}, \dots, a_1, a_0\) are real numbers, called the **coefficients**. The number \(a_0\), which is not multiplied by a variable, is called a **constant**. Each product \(a_nx^n\) is a **term of a polynomial**. The highest power of the variable that occurs in the polynomial is called the **degree** of a polynomial. The **leading** term is the term with the highest power, and its coefficient is called the **leading coefficient**.

When you learn about polynomials in algebra, the focus is on such things like identifying their degrees, factoring them, and solving different types of polynomials (trinomials, binomials, rational expressions, etc.) using the properties of numbers and other techniques. The rules are few, and you can review them here.

The value of polynomials is that they allow you to model more involved problems that might require some dexterous algebraic manipulations. The local behavior of a polynomial function is determined by its degree. A **turning point** is a point at which the function values change from increasing to decreasing or viceversa. A polynomial function of \(n^{th}\) degree is the product of \(n\) factors, so it will have at most \(n\) roots. The graph of a polynomial function of degree \(n\) will have \(n -1\) turning points and \(n\) \(x\)-intercepts.

```
def polynomial(x):
return 2 * x ** 3 - 4 * x ** 2 + x + 1
p = [polynomial(x) for x in range(-5, 8)]
plt.plot(range(-5, 8), p, label="$f(x) = 2x^3 - 4x^2 + x + 1$")
plt.legend(frameon=False)
```

A **power function** is a function with a single term that is the product of a real number, a **coefficient**, and a variable raised to a fixed real number.

\[f(x) = ax^n\]

With power functions, as \(x\) approaches positive or negative infinity, the \(f(x)\) values increase without bound.

\[\text{as } x \to \pm \infty, f(x) \to \infty\]

The graphs of even-powered functions resemble those of quadratic functions. However, as the power increases, the graphs flatten near the origin and become steeper away from the origin.

```
def power(x):
return x ** 4
p = [power(x) for x in range(-5, 8)]
plt.plot(range(-5, 8), p, label="$f(x) = x^4$")
plt.legend(frameon=False)
```

A **rational function** is a function that is given by the quotient, or ratio, of two polynomials. Technically, every polynomial function is also a rational function.

With rational functions, \(y\) **varies inversely** as \(x\).

```
def rational(x):
return (x ** 2 - 9) / (x - 3)
p = [rational(x) for x in range(4, 8)]
plt.plot(range(4, 8), p, label="$f(x) = x^2 - 9 / x - 3$")
plt.legend(frameon=False)
```

There’s also a special case of rational function, called **reprecipocal**, given by

\[f(x) = 1/x\]

```
def rational2(x):
return 1 / x
p = [rational2(x) for x in [-3, -2, -1, 1, 2, 3]]
plt.scatter([-3, -2, -1, 1, 2, 3], p, label="$f(x) = 1/x$")
plt.legend(frameon=False)
```

The absolute value of a number is its distnace from 0 on the number line. The **absolute-value function** is given by

\[f(x) = |x|\] and has a very distinctive V shape. We can think of this function as being defined piecewise by considering the definition of absolute value.

\[ f(x) = |x| = \left\{ \begin{array}{ll} x & \quad \text{if } x \geq 0 \\ -x & \quad \text{if } x < 0 \end{array} \right. \]

```
def absolute(x):
return abs(x)
p = [absolute(x) for x in range(-3, 4)]
plt.plot(range(-3, 4), p, label="$f(x) = |x|$")
plt.legend(frameon=False)
```

The **square root function** is given by

\[f(x) = \sqrt{x}\] It’s graph is half a parabola. This function can also be defined using exponent notation as \(f(x) = x^{\frac{1}{2}}\)

```
def root(x):
return math.sqrt(x)
p = [root(x) for x in range(0, 5)]
plt.plot(range(0, 5), p, label="$f(x) = \sqrt{x}$")
plt.legend(frameon=False)
```