# put your code here.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

x1 = np.arange(0.0,20.0,4.0)
y1 = np.sin(x1)

plt.plot(x1,y1,'r-')

"""
Explanation: Day 6 - pre-class assignment
INSTRUCTOR SOLUTIONS
Goals for today's pre-class assignment

Use numpy and pyplot to create some plots!
Write a simple loop using numpy

Assignment instructions
No need to watch any videos for this one.  Some useful resources are:

The Numpy module and numpy arrays (video)
The pyplot tutorial
The pyplot 'plot' command documentation -- this has instructions on how to change line color and type, and the shape of the line marker!

Recall that to make notebook cells that have Python code in them do something, hold down the 'shift' key and then press the 'enter' key (you'll have to do this to get the YouTube videos to run).  To edit a cell (to add answers, for example) you double-click on the cell, add your text, and then enter it by holding down 'shift' and pressing 'enter'
This assignment is due by 11:59 p.m. the day before class, and should be uploaded into the "Pre-class assignments" dropbox folder for Day 6.  Submission instructions can be found at the end of the notebook.
Question 1: In the cell below, use numpy's 'arange' method to create an array called 'x1' that goes from 0.0 to 20.0 with a stepsize of 4.0.  (hint: remember that you can look up how 'arange' works using the help() command or a question mark after the method name!).  After you do that, create an array called y1 that is equal to the sine of x1, using the numpy sine method (i.e., using np.sin() rather than the math module's sin() method).  Plot x1 and y2 with a red solid line.
End of explanation
"""


# put your code here.

x2 = np.arange(0.0,20.0,1.0)
y2 = np.sin(x2)

plt.plot(x1,y1,'r-',x2,y2,'b-')



"""
Explanation: Does the plot above  look like a sine function?  Why or why not?
No!  we're doing an awful job of sampling the sine function.
Question 2:  In the space below, use the same methods as before to make an array called x2 that goes from 0.0 to 20.0 with a stepsize of 1.0.  Then, create an array called y2 that's equal to the sine of x2.  Plot x1 vs. y1 and x2 vs. y2 on the same plot, using a red solid line for x1/y1 and a blue solid line for x2/y2.
End of explanation
"""


# put your code here

x3 = np.arange(0.0,20.0,0.1)
y3 = np.sin(x3)

plt.plot(x1,y1,'r-',x2,y2,'b-',x3,y3,'k--')



"""
Explanation: Question 3:  Finally do the same thing as above, but with a third array x3 that goes from 0.0 to 20.0 with a stepsize of 0.1, and an array y3 that is the sine of x3.  Plot all three functions on the same plot, using the same colors as above for x1/y1 and x2/y2, but a black dotted line (the symbol for black is 'k') for x3/y3.
End of explanation
"""


# put your code here!
import math

for val in np.nditer(x2):
    v1 = math.sin(val) + math.cos(val)
    v2 = math.sin(val)**2 + math.cos(val)**2
    print(val,v1,v2)

"""
Explanation: How did your plot of sin(x) change appearance as you decreased the spacing of your x-array from dx = 4.0 to dx = 0.1?  What does this tell you?
Put your answer here!
Question 4: Finally, write a small program that loops over the array x2, and for each value of x in x2 prints out x2, sin(x2) + cos(x2), and $\sin^2(\mathrm{x2}) + \cos^2(\mathrm{x2})$.
(Hint: don't forget the numpy nditer() method and the The numpy video from last week!)
End of explanation
"""


