# MAT 221 Calculus I

## April 9, 2020

Today's Agenda:
1. Finding The Domain of a Function
* Some Functions
  * Linear Functions
  * Power Functions
2. Exercises


```python
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
```

## Finding The Domain of a Function

### Definitions:
 * **Function:** A function $f$ is a rule that assigns to each element $x$ in the set $A$ exactly one element, called $f(x)$, in the set $B$. The set $A$ is called the domain and the set $B$ is called the range.
 * **Domain:** The domain of a function is the set of all real numbers for which the expression is defined as a real number. In other words, it is all the real numbers for which the expression "makes sense".
 <br>


```python
def sinc(x):
    y = []              # creates an empty list to store results
    for xx in x:        # loops over all elements in x array
        if xx==0.0:     # adds result of 1.0 to y list if
            y += [1.0]  # xx is zero
        else:           # adds result of sin(xx)/xx to y list if
            y += [np.sin(xx)/xx]  # xx is not zero
    return np.array(y)  # converts y to array and returns array

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-10, 10, 256)
y = sinc(x)

plt.plot(x, y)
plt.axhline(color="black", zorder=-1)
plt.axvline(color="black", zorder=-1)
plt.grid(True)

plt.show()
```


    <IPython.core.display.Javascript object>







```python

```

### Important Properties:
* Remember that you cannot have a zero in the denominator.
* Remember that you cannot have a negative number under an even root.
* Remember that we can evaluate an odd root of a negative number.

### Examples:

**Problem 1:** $$h(x)=\frac{x^{3}}{x^{2}+2x-3}$$ <br>

**Problem 2:** $$f(x)=\sqrt{6-4x}$$ <br>

## Some Functions

### Linear Functions

#### Definition: A linear function has the form: <br>
$$f(x)=mx+b, \ \ \ m \text{ and } b \text{ are constant}$$
Where 
\begin{align}
m &= \text{slope of graph of $f$} \\
b &= \text{y-intercept of graph of $f$}
\end{align}
**Graph of $f(x)$:** <br>
 <br>
**Example 1:** $f(x)=2x+1$ <br>
 <br>

**Point-Slope Equation of a Line** <br>
 <br>
**Example 2:** Find the equation of the line that passes through the points $(0, 2)$ and $(2, 3)$ <br>
$$y-y_{1}=m(x-x_{1}), \ \ \ \ \ (x_{1}=0, y_{1}=2), \text{ and } (x_{2}=2, y_{2}=3)$$ <br>
1. $m=\frac{y_{2}-y_{1}}{x_{2}-x_{1}}=\frac{3-2}{2-0}=\frac{1}{2}$
* $(x_{1}, y_{1})=(0, 2)$
* $y-2=\frac{1}{2}(x-0) \Rightarrow y=\frac{1}{2}x+2$

**Properties of a Line**
* **Slope of Positive, Negative, Zero and Undefined** <br>
 <br>
* **Parallel Lines** <br>
 <br>
* **Perpendicular Lines** <br>
 <br>


```python
x = np.linspace(-5, 5, 100)

# plot with various axes scales
#plt.figure()
plt.figure(num=None, figsize=(11, 3), dpi=80, facecolor='w', edgecolor='k')

plt.subplot(141)
y = x+1
plt.plot(x, y, color='r', linestyle='-')
plt.axhline(color="black", zorder=-1)
plt.axvline(color="black", zorder=-1)
plt.title('Positive Slope')
plt.grid(True)

plt.subplot(142)
y = -x+1
plt.plot(x, y, color='r', linestyle='-')
plt.axhline(color="black", zorder=-1)
plt.axvline(color="black", zorder=-1)
plt.title('Negative Slope')
plt.grid(True)

plt.subplot(143)
plt.axhline(y=0.5, color='r', linestyle='-')
plt.title('Zero Slope')
plt.grid(True)

plt.subplot(144)
plt.axvline(x=0.5, color='r', linestyle='-')
plt.title('Slope Undefined')
plt.grid(True)
# Adjust the subplot layout, because the logit one may take more space
# than usual, due to y-tick labels like "1 - 10^{-3}"
plt.subplots_adjust(top=0.9, bottom=.1, left=0.05, right=0.95, hspace=.5,
                    wspace=0.2)

plt.show()
```


    <IPython.core.display.Javascript object>







```python
x = np.linspace(-5, 5, 100)

# plot with various axes scales
#plt.figure()
plt.figure(num=None, figsize=(10, 5), dpi=80, facecolor='w', edgecolor='k')

plt.subplot(121)
y1 = .5*x+0.5
y2 = .5*x-1
plt.plot(x, y1, color='r', linestyle='-')
plt.plot(x, y2, color='b', linestyle='-')
plt.axhline(color="black", zorder=-1)
plt.axvline(color="black", zorder=-1)
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal', adjustable='box')
plt.title('Positive Slope')
plt.grid(True)

plt.subplot(122)
y3 = (1/2)*x-0.5
y4 = -2*x+0.5
plt.plot(x, y3, color='r', linestyle='-')
plt.plot(x, y4, color='b', linestyle='-')
plt.axhline(color="black", zorder=-1)
plt.axvline(color="black", zorder=-1)
plt.title('Negative Slope')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal', adjustable='box')
plt.grid(True)

#plt.subplots_adjust(top=0.9, bottom=.1, left=0.01, right=1, hspace=1,
#                    wspace=0.3)

plt.show()
```


    <IPython.core.display.Javascript object>






### Power Functons

#### Definition: A power function has the form: <br>
$$f(x)=kx^{r}, \ \ \ k \text{ and } r \text{ are constants}$$
Note: $r$ can be any real number. <br>
**Examples:** $f(x)=\frac{1}{3}x^{\pi}, \ \ \ f(x)=\sqrt{2}x^{-1}, \ \ \ f(x)=x^{\frac{3}{5}}，\ \ \ f(x)=2x^{3}$ 


#### The Graphs of Power Functions:

* **$r=$ Odd or Even Positive Integer** <br>

* **$r=0, 1, -1$** <br>

* **$r=$ Odd or Even Negative Integer (including $r=-1$)** <br>

* **$r=$ Positive Fractions** <br>


Exercise:






```python
import plotly.graph_objs as go
import numpy as np
#from ipywidgets import interact, interactive
from ipywidgets import widgets
from IPython.display import display

aSlider = widgets.FloatSlider(
    value=2.0,
    min=1.0,
    max=4.0,
    step=0.01,
    description='a:',
    continuous_update=False
)

bSlider = widgets.FloatSlider(
    value=1.0,
    min=0.0,
    max=10.0,
    step=0.01,
    description='b:',
    continuous_update=True
)

colorDropdown = widgets.Dropdown(
    description='Color:',
    value='blue',
    options=['red', 'blue', 'green']
)

fig = go.FigureWidget()
#fig.show()
scattf = fig.add_scatter()
scatt = scattf.data[-1]

xs=np.linspace(0, 6, 100)

def response(change):
    with fig.batch_update():
        fig.data[0].x=xs
        fig.data[0].y=np.sin(aSlider.value*xs-bSlider.value)
        fig.data[0].line.color=colorDropdown.value
        fig.layout.xaxis.title = 'whatever'

aSlider.observe(response, names="value")
bSlider.observe(response, names="value")
colorDropdown.observe(response, names="value")

response("doesn't matter what I send here, just triggering") # MUST be before widgets.VBox - if response(x) is last, NOTHING is drawn! 

widgets.VBox([aSlider,
              bSlider,
              colorDropdown,
              fig])
```


    VBox(children=(FloatSlider(value=2.0, continuous_update=False, description='a:', max=4.0, min=1.0, step=0.01),…



```python
import numpy as np
import plotly.graph_objects as go
from ipywidgets import interact

xs=np.linspace(0, 2*np.pi, 200)

fig = go.FigureWidget()
fig.add_scatter()

@interact(a=(1.0, 4.0, 0.01), b=(0, 10.0, 0.01), color=['red', 'green', 'blue'])
def update(a=3.6, b=4.3, color='blue'):
    with fig.batch_update():
        fig.data[0].x=xs
        fig.data[0].y=np.sin(a*xs-b)
        fig.data[0].line.color=color
fig
```


    interactive(children=(FloatSlider(value=3.6, description='a', max=4.0, min=1.0, step=0.01), FloatSlider(value=…



    FigureWidget({
        'data': [{'line': {'color': 'blue'},
                  'type': 'scatter',
                  'uid': …



```python

```

ef2124531509c4629bc5bf50450da87f7e2f24b5
ipynb
Jupyter Notebook
Jupyter_Notes/Lecture01_Function_Review(1).ipynb
xiuquan0418/MAT221
bca0bd815a6c82325ebbacbfca3a15c4cbdc24f0
MIT
2020-05-07T07:18:11.000Z
2020-05-07T07:18:11.000Z
Jupyter_Notes/Lecture01_Function_Review(1).ipynb
xiuquan0418/MAT221
bca0bd815a6c82325ebbacbfca3a15c4cbdc24f0
MIT
Jupyter_Notes/Lecture01_Function_Review(1).ipynb
xiuquan0418/MAT221
bca0bd815a6c82325ebbacbfca3a15c4cbdc24f0
MIT
Qwen/Qwen-72B
1. YES
2. YES