# Linear Vs. Non-Linear Functions
** October 2017 **

** Andrew Riberio @ [AndrewRib.com](http://www.andrewrib.com) **

Resources
* https://en.wikipedia.org/wiki/Linear_function
* https://www.montereyinstitute.org/courses/Algebra1/COURSE_TEXT_RESOURCE/U03_L2_T5_text_final.html
* https://en.wikipedia.org/wiki/Linear_combination

## Libraries


```python
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
```

## Linear Functions 

A linear function of one variable has the geometric interpretation as a line when we plot the space of inputs against the output space: y = f(x). In three dimensions, in 3d space, we can do a similar thing z = f(x,y), but we arrive at the generalization of a line in 3d space called a *plane.*


```python
# There are no functions in one dimension since we cannot deliniate inputs/outputs. 
# A single dimension is just a constant value of existence with no notion of difference. 

# Two dimensional funciton
def f2(x):
    return x

# Three dimensional funciton. Output is z.
def f3(x,y):
    return x + y

# Four dimensional function. We cannot visualize this easily. 
def f4(x,y,z):
    return x + y + z

t1 = np.arange(0.0, 5.0, 0.1)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f2(t1))

X,Y = np.meshgrid(t1,t1)

plt.subplot(212,projection="3d")

plt.plot(X,Y, f3(t1,t1))

plt.show()
```

**Theorem:** The derivitive of every linear function is a constant.


```python
x_sym, y_sym = sp.symbols('x y')
print("dy/dx f2 = {0}".format(sp.diff(f2(x_sym))))
print("∂z/∂x f3 = {0}".format(sp.diff(f3(x_sym,y_sym),x_sym)))
```

    dy/dx f2 = 1
    ∂z/∂x f3 = 1


**Definition:** A *linear combination* of varibles (x<sub>1</sub>, x<sub>2</sub>, ... , x<sub>n</sub>) = ∂<sub>1</sub>x<sub>1</sub> + ∂<sub>2</sub>x<sub>2</sub>+ ... + ∂<sub>n</sub>x<sub>n</sub> where ∂ are constants.

**Theorem:** All linear functions can be represented as a linear combination. 


## Non-Linear Functions

Non-linear functions are more unpredictable than linear functions because the derivitive of a non-linear function is always a function, not a constant. The geometric interpretation of non-linear functions encompasses the diverse space of curves. 


```python
# Two dimensional funciton
def f2(x):
    return x**2

# Three dimensional funciton. Output is z.
def f3(x,y):
    return x * y

t1 = np.arange(0.0, 5.0, 0.1)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f2(t1))

plt.subplot(212,projection="3d")
X,Y = np.meshgrid(t1,t1)
plt.plot(X,Y, f3(t1,t1))
plt.show()
```

**Theorem:** The derivitive of every non-linear function is **not a constant**.



```python
x_sym, y_sym = sp.symbols('x y')
print("dy/dx f2 = {0}".format(sp.diff(f2(x_sym))))
print("∂z/∂x f3 = {0}".format(sp.diff(f3(x_sym,y_sym),x_sym)))
```

    dy/dx f2 = 2*x
    ∂z/∂x f3 = y


**Theorem:** Non-linear functions cannot be represented by a linear combination.


64a4f5c25499c5496728d5c87a37a5e551d60934
ipynb
Jupyter Notebook
Notebooks/Linear Vs. Non-Linear Functions.ipynb
Andrewnetwork/WorkshopScipy
739d24b9078fffb84408e7877862618d88d947dc
MIT
2017-12-16T20:50:07.000Z
2021-11-08T13:05:57.000Z
Notebooks/Linear Vs. Non-Linear Functions.ipynb
Andrewnetwork/WorkshopScipy
739d24b9078fffb84408e7877862618d88d947dc
MIT
2017-12-17T06:10:28.000Z
2018-11-14T15:50:10.000Z
Notebooks/Linear Vs. Non-Linear Functions.ipynb
Andrewnetwork/WorkshopScipy
739d24b9078fffb84408e7877862618d88d947dc
MIT
2017-12-06T20:40:09.000Z
2019-06-01T11:33:57.000Z
Qwen/Qwen-72B
1. YES
2. YES