# Pre-Calculus Notebook


```python
# Begin with some useful imports
import numpy as np
import pylab
from fractions import Fraction
from IPython.display import display, Math
from sympy import init_printing, N, pi, sqrt, symbols, Symbol
from sympy.abc import x, y, theta, phi
init_printing(use_latex='mathjax')  # do this to allow sympy to print mathy stuff
%matplotlib inline
```

## Trig Functions

This notebook will introduce basic trigonometric functions.

Given an angle, θ, there are two units used to indicate the measure of the angle: degrees and radians.

### First make a simple function to convert from degrees to radians


```python
def deg_to_rad(angle, as_expr=False):
    """ Convert degrees to radians 
        param: theta: degrees as a float or numpy array of values that can be cast to a float
        param: as_text: True/False output as text with multiple of 'π' (Default = False)
        
        The formula for this is:
        2πθ/360°
        
        Note: it's usually bad form to allow a function argument to change an output type.  Oh, well.
    """
    radians = (angle * 2 * np.pi) / 360.0
    
    if as_expr:
        # note: this requires sympy
        radians = 2*pi*angle/360
    
    return radians
```


```python
# Test our function
# Note: normally you would print results, but with sympy expressions, 
#       the `display` function of jupyter notebooks is used to print using MathJax.

display(deg_to_rad(210, as_expr=True))
display(deg_to_rad(360, as_expr=True))

```


$$\frac{7 \pi}{6}$$



$$2 \pi$$


### Now, let's make a list of angles around a unit circle and convert them to radians


```python
base_angles = [0, 30, 45, 60]
unit_circle_angles = []
for i in range(4):
    unit_circle_angles.extend(np.array(base_angles)+(i*90))
unit_circle_angles.append(360)
```


```python
# make a list of the angles converted to radians (list items are a sympy expression)
unit_circle_angles_rad = [deg_to_rad(x, False) for x in unit_circle_angles]
unit_circle_angles_rad_expr = [deg_to_rad(x, True) for x in unit_circle_angles]
```


```python
unit_circle_angles_rad
```




$$\left [ 0.0, \quad 0.523598775598, \quad 0.785398163397, \quad 1.0471975512, \quad 1.57079632679, \quad 2.09439510239, \quad 2.35619449019, \quad 2.61799387799, \quad 3.14159265359, \quad 3.66519142919, \quad 3.92699081699, \quad 4.18879020479, \quad 4.71238898038, \quad 5.23598775598, \quad 5.49778714378, \quad 5.75958653158, \quad 6.28318530718\right ]$$




```python
unit_circle_angles_rad_expr
```




$$\left [ 0, \quad \frac{\pi}{6}, \quad \frac{\pi}{4}, \quad \frac{\pi}{3}, \quad \frac{\pi}{2}, \quad \frac{2 \pi}{3}, \quad \frac{3 \pi}{4}, \quad \frac{5 \pi}{6}, \quad \pi, \quad \frac{7 \pi}{6}, \quad \frac{5 \pi}{4}, \quad \frac{4 \pi}{3}, \quad \frac{3 \pi}{2}, \quad \frac{5 \pi}{3}, \quad \frac{7 \pi}{4}, \quad \frac{11 \pi}{6}, \quad 2 \pi\right ]$$




```python
# show the list of angles in degrees
unit_circle_angles
```




$$\left [ 0, \quad 30, \quad 45, \quad 60, \quad 90, \quad 120, \quad 135, \quad 150, \quad 180, \quad 210, \quad 225, \quad 240, \quad 270, \quad 300, \quad 315, \quad 330, \quad 360\right ]$$



### So, what are radians

Radians are a unit of angle measure (similar to degrees).  Radians correspond to the chord length that an angle sweeps out on the unit circle.  A complete circle with a radius of 1 (a unit circle) has a circumference of $2\pi$ (from the formula for circumference: $C = 2\pi r$ )

Let's import some things to help us create a plot to see this in action.


```python
from bokeh.plotting import figure, show, output_notebook
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="02880136-3f1b-402b-af8a-963faef89115">Loading BokehJS ...</span>
</div>




If you were to map out our angle values on the circle drawn on a cartesian coordinate grid, it might look like this:


```python
p = figure(plot_width=600, plot_height=600, match_aspect=True)


# draw angle lines
x = np.cos(unit_circle_angles_rad)
y = np.sin(unit_circle_angles_rad)
origin = np.zeros(x.shape)


for i in range(len(unit_circle_angles_rad)):
    #print (x[i], y[i])
    p.line((0, x[i]), (0, y[i]))

# draw unit circle
p.circle(0,0, radius=1.0, color="white", line_width=0.5, line_color='black',
         alpha=0.0, line_alpha=1.0)

```




<div style="display: table;"><div style="display: table-row;"><div style="display: table-cell;"><b title="bokeh.models.renderers.GlyphRenderer">GlyphRenderer</b>(</div><div style="display: table-cell;">id&nbsp;=&nbsp;'fc41fd69-f9b1-4846-b0a5-77bea065dad0', <span id="374ae5d9-71d0-4083-964f-84f23fa58419" style="cursor: pointer;">&hellip;)</span></div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">data_source&nbsp;=&nbsp;ColumnDataSource(id='d578de05-1c57-4568-bf26-45bbd7e91071', ...),</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">glyph&nbsp;=&nbsp;Circle(id='c04870c5-f214-4e3c-8b2a-9ca556962ac3', ...),</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">hover_glyph&nbsp;=&nbsp;None,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">js_event_callbacks&nbsp;=&nbsp;{},</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">js_property_callbacks&nbsp;=&nbsp;{},</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">level&nbsp;=&nbsp;'glyph',</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">muted&nbsp;=&nbsp;False,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">muted_glyph&nbsp;=&nbsp;None,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">name&nbsp;=&nbsp;None,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">nonselection_glyph&nbsp;=&nbsp;Circle(id='e17f1a11-aaf3-46df-8b18-671e96ef5549', ...),</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">selection_glyph&nbsp;=&nbsp;None,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">subscribed_events&nbsp;=&nbsp;[],</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">tags&nbsp;=&nbsp;[],</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">view&nbsp;=&nbsp;CDSView(id='86474633-4aeb-4e71-bd74-6de289e9ebd8', ...),</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">visible&nbsp;=&nbsp;True,</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">x_range_name&nbsp;=&nbsp;'default',</div></div><div class="9c5f3898-0b91-4981-9833-9b8d7c09ad7b" style="display: none;"><div style="display: table-cell;"></div><div style="display: table-cell;">y_range_name&nbsp;=&nbsp;'default')</div></div></div>






```python
show(p)
```



<div class="bk-root">
    <div class="bk-plotdiv" id="5de3f74f-d8a6-4d67-971f-401cdca919b0"></div>
</div>





```python
import bokeh
```


```python
bokeh.__version__
```




    u'0.12.7'




```python
    from bokeh.plotting import figure, output_file, show

    output_file("circle_v1.html")

    p = figure(plot_width=400, plot_height=400, match_aspect=True, tools='save')
    p.circle(0, 0, radius=1.0, fill_alpha=0)
    p.line((0, 1), (0, 0))
    p.line((0, -1), (0, 0))
    p.line((0, 0), (0, 1))
    p.line((0, 0), (0, -1))
    #p.rect(0, 0, 2, 2, fill_alpha=0)

    show(p)
    
```



<div class="bk-root">
    <div class="bk-plotdiv" id="dba7c216-ec39-4fcf-b8e8-f9858fa4d7f0"></div>
</div>





```python
import sys, IPython, bokeh
print "Python: ", sys.version
print "IPython: ", IPython.__version__
print "Bokeh: ", bokeh.__version__
```

    Python:  2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
    IPython:  5.3.0
    Bokeh:  0.12.10



```python
%reload_ext version_information
```


```python
%version_information
```




<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>2.7.13 64bit [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]</td></tr><tr><td>IPython</td><td>5.3.0</td></tr><tr><td>Bokeh</td><td>0.12.10</td></tr><tr><td>OS</td><td>Darwin 17.2.0 x86_64 i386 64bit</td></tr><tr><td colspan='2'>Wed Nov 15 13:14:25 2017 CST</td></tr></table>




```python
from bokeh.plotting import figure, output_file, show
from bokeh.layouts import layout

p1 = figure(match_aspect=True, title="Circle touches all 4 sides of square")
#p1.rect(0, 0, 300, 300, line_color='black')
p1.circle(x=0, y=0, radius=10, line_color='black', fill_color='grey',
          radius_units='data')

def draw_test_figure(aspect_scale=1, width=300, height=300):
    p = figure(
        plot_width=width,
        plot_height=height,
        match_aspect=True,
        aspect_scale=aspect_scale,
        title="Aspect scale = {0}".format(aspect_scale),
        toolbar_location=None)
    p.circle([-1, +1, +1, -1], [-1, -1, +1, +1])
    return p

aspect_scales = [0.25, 0.5, 1, 2, 4]
p2s = [draw_test_figure(aspect_scale=i) for i in aspect_scales]

sizes = [(100, 400), (200, 400), (400, 200), (400, 100)]
p3s = [draw_test_figure(width=a, height=b) for (a, b) in sizes]

layout = layout(children=[[p1], p2s, p3s])

output_file("aspect.html")
show(layout)
```



<div class="bk-root">
    <div class="bk-plotdiv" id="4bcb865a-e518-422b-a1c4-bcfed863bb9e"></div>
</div>





```python

```

cb68782ba649ecec9dd9eae09a0be3f082aeb349
ipynb
Jupyter Notebook
math/PreCalculus.ipynb
tvaught/education
f96f12c178ab353957bf1ab26eeb302c4f272eea
MIT
math/PreCalculus.ipynb
tvaught/education
f96f12c178ab353957bf1ab26eeb302c4f272eea
MIT
math/PreCalculus.ipynb
tvaught/education
f96f12c178ab353957bf1ab26eeb302c4f272eea
MIT
Qwen/Qwen-72B
1. YES
2. YES