# Week 1
### Section 0.3, problem 7

[link to relevant section of the book](http://scidiv.bellevuecollege.edu/dh/Calculus_all/CC_0_3_functions)

$f(x) = x^2 + 3$ , $g(x) = \sqrt{x - 5}$ , and $h(x) = \frac{x}{x - 2}$

### (a) evaluate $f(1)$, $g(1)$, and $h(1)$


```python
import math
import numpy as np

def f(x):
    return x**2 + 3

def g(x):
    if x-5 >= 0:
        return math.sqrt(x-5)
    else:
        return str(abs(x-5))+'i'


def h(x):
    try:
        return x/(x-2)
    except ZeroDivisionError:
        return np.NaN

print(
    "f of 1:", f(1),
    "\ng of 1:", g(1),
    "\nh of 1:", h(1)
)
```

    f of 1: 4 
    g of 1: 4i 
    h of 1: -1.0


###  (b) graph f(x), g(x) and h(x) for $-5 \le x \le 10$


```python
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from bokeh.layouts import row

output_notebook()
```



<div class="bk-root">
    <a href="https://bokeh.pydata.org" target="_blank" class="bk-logo bk-logo-small bk-logo-notebook"></a>
    <span id="1095">Loading BokehJS ...</span>
</div>





```python
# plot of f(x)
p = figure(plot_width=300, plot_height=300, 
           tools='pan,wheel_zoom,reset', title="f(x) plot")

x = [x/100 for x in range(-500, 1100)]
y = [f(num) for num in x]

p.line(x, y, line_width=2)


#plot of g(x)
p2 = figure(plot_width=300, plot_height=300, 
            tools='pan,wheel_zoom,reset', title="g(x) plot")

x = [x/100 for x in range(-500, 1100)]
y = [g(num) for num in x]

p2.line(x, y, line_width=2)


#plot of h(x)
p3 = figure(plot_width=300, plot_height=300, 
            tools='pan,wheel_zoom,reset', title="h(x) plot")

x = [x/100 for x in range(-500, 1100)]
y = [h(num) for num in x]

p3.line(x, y, line_width=2)

show(row(p, p2, p3))
```








<div class="bk-root" id="bc0dfcb2-a270-400e-bd1c-08b3ec59bd5d" data-root-id="1457"></div>





### (c) evaluate f(3x), g(3x), and h(3x)


```python
import sympy

# set printing to unicode/latex
sympy.init_printing(use_unicode=True)
```


```python
# define our symbols
x = sympy.symbols('x')

# make our functions using sympy
f = x**2 + 3
g = sympy.sqrt(x-5)
h = x / (x-2)
```


```python
# evaluate functions
f.subs(x, 3*x)
```


```python
g.subs(x, 3*x)
```


```python
h.subs(x, 3*x)
```

### evaluate $f(x+h)$, $g(x+h)$, and $h(x+h)$
(assuming the $h$ in $h(x+h)$ is a separate number)


```python
# I'll assign the symbol 'h' to the variable y
y = sympy.symbols("h") 

f.subs(x, x+y)
```


```python
g.subs(x, x+y)
```


```python
h.subs(x, x+y)
```

91ff138e87eba8da3250788367e37974af3b66cd
ipynb
Jupyter Notebook
week1/section_03_problem_07.ipynb
MaraudingAvenger/Math140
bddf788d370d1b1fe9db6f495261cbfc096197e0
MIT
week1/section_03_problem_07.ipynb
MaraudingAvenger/Math140
bddf788d370d1b1fe9db6f495261cbfc096197e0
MIT
week1/section_03_problem_07.ipynb
MaraudingAvenger/Math140
bddf788d370d1b1fe9db6f495261cbfc096197e0
MIT
Qwen/Qwen-72B
1. YES
2. YES