# YO WHADDUP BRO LET'S DO SOME CALCULUS



Remember last time, we talked about how cows are cool and often loosely correlated to math?
```
                                       /;    ;\
                                   __  \____//
                                  /{_\_/   `'\____
                                  \___ ---(=)--(=)--}
       _____________________________/          :--'
   ,-,'`@@@@@@@@       @@@@@@         \_    `__\
  ;:(  @@@@@@@@@        @@@             \___(o'o)
  :: )  @@@@          @@@@@@        ,'@@(  `===='
  :: : @@@@@:          @@@@         `@@@:
  :: \  @@@@@:       @@@@@@@)    (  '@@@'
  ;; /\      /`,    @@@@@@@@@\\   :@@@@@)
  ::/  )    {_----------------:  :~`, ;
 ;;'`; :   )                  :  / `; ;
;;;; : :   ;                  :  ;  ; :
`'`' / :  :                   :  :  : :
    )_ \__;      ";"          :_ ;  \_\       `,','
    :__\  \    * `,'*         \  \  :  \   *  8`;'*  *
        `^'     \ :/           `^'  `-^-'   \v/ :  \/   -Bill Ames-     
```


```python
import matplotlib.pyplot as plt
import numpy as np
import sympy
```

Well, this time we're going to go deeper. So let's begin ***with a few questions***

# What do we mean by the phrase "rate of change"?



```python
""" The change of change """
```

# What do we call the "rate of change" of position?


```python
""" velocity / speed """
```

# What do we call the "rate of change" of velocity/speed?


```python
""" acceleration """
```




    ' acceleration '





Finally,
# What 1-word definition can we use for the phrase "rate of change"?

Whatever you chose, TOO BAD ***HAHAHAHA***, we are going to use a term clearly invented by mathematicians:
    
## The DERIVATIVE == "The rate of change"



And, even more specifically

***Suppose we have a function we call "f", taking an input "x" because we have no imagination***:
## $f(x)$

***The DERIVATIVE of f with respect to x == "The rate of change of f as x changes"***:
## $\frac{df(x)}{dx} = f'(x)$

#### There are also higher derivatives, like the 2nd and 3rd and Nth derivative:

## $\frac{df^2(x)}{dx}  = f''(x)$
## $\frac{df^3(x)}{dx}  = f'''(x)$
## $\frac{df^n(x)}{dx}  = f^n(x)$ for any $n$

#### When taking these derivatives from position, like we were saying earlier:
## $x(t) = position$
## $\frac{dx(t)}{dt}  = x'(t) = velocity$
## $\frac{dx^2(t)}{dt}  = x''(t) = acceleration$
## $\frac{dx^3(t)}{dt}  = x'''(t) = jerk$
## $\frac{dx^4(t)}{dt}  = x''''(t) = jounce$
## $\frac{dx^5(t)}{dt}  = x'''''(t) = snap$
## $\frac{dx^6(t)}{dt}  = x''''''(t) = crackle$
## $\frac{dx^7(t)}{dt}  = x'''''''(t) = pop$
## $\frac{dx^8(t)}{dt}  = x''''''''(t) = lock$
## $\frac{dx^9(t)}{dt}  = x''''''''(t) = drop$



# Quick example! 
- We have a function sin(x) / x telling us the position of a pendulum over time
- Let's see what it's speed graph looks like
- And also it's acceleration graph!


```python
# create a "symbol" called "t", for time (think of this like writing "t" on a piece of paper)
t = sympy.Symbol('t') 

# sympy.exp IS the e to the power of x function. "exp" = e**x
g = 0.1
r = 3
position = -(g * t**r - 1)**2 + 1

tvals = np.linspace(1, 2.8,1000)

velocity     = sympy.lambdify(t, sympy.diff(position, t), modules=['numpy'])
acceleration = sympy.lambdify(t, sympy.diff(sympy.diff(position, t), t), modules=['numpy'])

pos_call     = sympy.lambdify(t, position, modules=['numpy'])

plt.plot(tvals, pos_call(tvals))
plt.xlabel('x axis')
plt.ylabel('position!')
```


```python
plt.plot(tvals, velocity(tvals))
plt.xlabel('x axis')
plt.ylabel('velocity!')
```


```python
plt.plot(tvals, acceleration(tvals))
plt.xlabel('x axis')
plt.ylabel('acceleration!')
```

#### Now, I want you to try and graph the "jerk", and the "jounce" as well


```python


# PUT YOUR CODE HERE!
jerk = sympy.lambdify(t, sympy.diff( 
                                sympy.diff(
                                            sympy.diff(position, t), t) , t), modules=['numpy'])

jounce = sympy.lambdify(t, sympy.diff( 
                                sympy.diff( 
                                    sympy.diff(
                                            sympy.diff(position, t), t) , t), t), modules=['numpy'])

plt.plot(tvals, jerk(tvals))
plt.xlabel('x axis')
plt.ylabel('jerk!')
```


```python
plt.plot(tvals, jounce(tvals))
plt.xlabel('x axis')
plt.ylabel('jounce!')
```

----
----
# Now, let's meet a new number:

- Like $\pi$, this number is "transcendental"...
- It never repeats in any macro or micro structure, as far as ever examined

It is:
## $ e  \approx 2.71$

***And I have a confession... ***




```python
import numpy as np
np.e * np.e
```




    7.3890560989306495



# Now, let's meet a new function, using $e$:

# $f(x) = e^x$

#### On a graph, it looks like this...


```python
x = sympy.Symbol('x')  # create a "symbol" called "x" (think of this like writing "x" on a piece of paper)
function = sympy.exp(x)  # sympy.exp IS the e to the power of x function. "exp" = e**x
```


```python
xvals = np.linspace(-1,1,100)
use_function = sympy.lambdify(x, function, modules=['numpy'])
plt.plot(xvals, use_function(xvals))
plt.xlabel('x axis')
plt.ylabel('y = f(x) axis')
```

# Now, let's use our new knowledge of derivatives to see "how fast" $e^x$ changes! 
## In writing:

## $\frac{df(x)}{dx} = \frac{d}{dx} (e^x)$


```python
# In code:
derivative = sympy.diff(expression, x)  # let sympy do the work of taking the derivative of e to the x
```


```python
derivative
```

# Wait.... What? Do you see what happened?

#### Let's try this again...


```python
# In code:
derivative = sympy.diff(function, x)  # let sympy do the work of taking the derivative of e to the x
derivative
```




    exp(x)





#### What if... We take the derivative of the derivative?
- This is called the "second derivative"


```python
# In code:
derivative = sympy.diff(sympy.diff(function, x), x)  # let sympy do the work of taking the derivative of e to the x
derivative
```




    exp(x)



#### And again?


```python
# In code:
derivative = sympy.diff(sympy.diff(sympy.diff(derivative, x),x),x)  # let sympy do the work of taking the derivative of e to the x
derivative
```




    exp(x)



# FYI, this is the part where your mind explodes



# ICYMI, the derivative of this...


```python
xvals = np.linspace(-1,1,100)
use_function = sympy.lambdify(x, function, modules=['numpy'])
plt.plot(xvals, use_function(xvals))
plt.xlabel('x axis')
plt.ylabel('y = f(x) axis')
```

# Is this...


```python
xvals = np.linspace(-1,1,100)
use_derivative = sympy.lambdify(x, derivative, modules=['numpy'])
plt.plot(xvals, use_function(xvals))
plt.xlabel('x axis')
plt.ylabel('y = f(x) axis')
```


```python

```


```python

```


```python

```


```python

```


```python

```

73ee2c256454fcdd6592d9fa7da997daebde948f
ipynb
Jupyter Notebook
Math Magic/Week15_Notebook.ipynb
jonnyhyman/Programming-Classes
f56a9cf90e3b8e4aafad99644f1ed7e87ba14995
MIT
2018-12-15T01:10:51.000Z
2021-07-02T05:23:45.000Z
Math Magic/Week15_Notebook.ipynb
jonnyhyman/Programming-Classes
f56a9cf90e3b8e4aafad99644f1ed7e87ba14995
MIT
Math Magic/Week15_Notebook.ipynb
jonnyhyman/Programming-Classes
f56a9cf90e3b8e4aafad99644f1ed7e87ba14995
MIT
2020-02-15T12:47:42.000Z
2021-02-28T03:01:19.000Z
Qwen/Qwen-72B
1. YES
2. YES