import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

# Defines an x vector, going from 0 to 2 pi in 20 steps
x = np.linspace(start=0, stop=2*np.pi, num=20)

plt.plot(x, np.sin(x), label='Sin') # Plot sin
plt.plot(x, np.cos(x), 'o-', label='Cos') # Plot cos

plt.legend() # add a legend to the plot

print("We made this vector x:")
print(x) # print the vector we made

"""
Explanation: Welcome to Phys 77

Who am I?
Dar, PhD student in Physics, working in experimental quantum computing, Quantum Nanoelectronic Lab.
DarDahlen@berkeley.edu
150 LeConte - W 4-6pm
My programming rules of thumb:
0) If you don't understand why it's working, you aren't done yet
 1) Google is your friend 
 2) Someone, somewhere, has already tried to do what I'm trying to do
 3) Guess and check works suprisingly well
 4) RTFM  (Read the Manual)

What are we doing?


The Course - 10k Foot View:
    What is not clear here will be explained in more detail on Monday. If you can't wait till then, the syllabus is on bcourses.berkeley.edu

Lectures - Mondays
Workshops - Fridays (40% of your grade, required attendence)
Homework (mostly python based, 40% of grade)
Final Project (20% of grade)



Workshops Specifically - Friday afternoons: 
    I am in charge of workshops, these will mostly be pair programming, working on homework or workshop specific assignments.  When a programming homework assignment is given out, I will randomly assign you into pairs (using python), each homework will be treated as a pair assignment, where you will each recieve the same grade. During workshops when there are homework assignments, we will be practicing pair programming, where one person "drives" and the other person gives advice.


Today:
    Today will be largely an introduction, explanation, and installation of Python.

There is a sign-in sheet, sign in or you wont get credit for attendance today!
Github Repo for Workshops - Where you can download the notebooks used in this class - https://github.com/dahlend/Physics77Fall17
Anaconda Python - Probably the most common way of installing python. - https://www.continuum.io/downloads




Goals for Today:
0) You can download this notebook from   github.com/dahlend/Physics77Fall17
1) Install Python 3.6 (via Anaconda)
2) Get Jupyter Running
3) Write a simple program
4) Bonus Problems at the bottom if you get bored

Step 0 - Open this notebook
github.com/dahlend/Physics77Fall17
Click on "Workshop 1 - Introduction"
Step 1 - What is Anaconda?
Anaconda is a pre-packaged python that includes effectively all the tools we will use in this course. In addition, it allows us to install librarys we are missing in a very simple manner.
Step 1 of today will be downloading and installing Anaconda.
https://www.continuum.io/downloads
Download and install Python 3.6 appropriate for your OS.
Step 2 - Run Jupyter
Jupyter is a an interface for making it easy to run Python and see your result. This 'website' is actually a jupyter notebook.
I'll show you what you can do:
End of explanation
"""


# Code comments start with a # symbol, which means python ignores the line after it

# Many tools you need are in things called Libraries/Packages/Modules, 
# these libraries are often built for free by hobbyists

# Python's primary plotting library is called matplotlib

# Librarys are just Folders in your computer stored in a specific location
# you can get to sub-folders with a . like so:

# You will see this line of code very very often:
import matplotlib.pyplot as plt 

# this essentially imports a folder called pyplot from the folder matplotlib
# but since the name is kind of long, we can say import it but call it something
# else, in this case we are calling it plt



# another tool we will use very very often is Numpy
# numpy is short for numerical python
import numpy as np

# as you google more and more you will see it is common practice to call
# these libraries by thier short names, np and plt


# This next line is not actually python, it is Jupyter
%matplotlib inline
# anytime you see a line start with % it is telling 
# jupyter to do something, in this case we are telling 
# jupyter that we are using matplotlib library, and we want plots "inline"
# which means it plots it in the jupyter notebook.



# Defines an x vector of 20 number, going from 0 to 2 pi
x = np.linspace(start=0, stop=2*np.pi, num=20)

"""
Explanation: Now that you have anaconda installed, we will open a jupyter notebook.
- if you are on mac/unix open "terminal"
- If you are on windows open "command prompt"
Then type in:
jupyter notebook
Step 3 - Run a simple program
Take copy the code from above and run it, (shift + enter or ctrl + enter).
Play around with it, delete a line, see what happens, programming is often a trial and error excercise.
Bonus Problems -
Days where we don't have assigned homework will often include a bonus problem. These problems will often be at or beyond the limits of what have currently been covered in class. Don't feel bad if you currently have NO idea how to do it, by the end of the semester you should have the tools needed to attempt them!
Bonus 0 -
Plot an exponential decay of the form:
$y = e^{-t}$  
With t going from 0 to 5.  
Label the x-axis and y-axis appropriately, and put a title on the plot.  
You might have to do some googling for this, the plotting tool we are using is called matplotlib.
Bonus 1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Step 2 in Detail
End of explanation
"""


help(np.linspace) # Very helpful!

plt.plot(x, np.sin(x), label='Sin') # Plot sin
plt.plot(x, np.cos(x), 'o-', label='Cos') # Plot cos

plt.legend() # add a legend to the plot

print("We made this vector x:")
print(x) # print the vector we made

help(plt.plot) # This one is super long

"""
Explanation: What is going on here?
We are calling np.linspace, which is a function from the numpy library.
Python functions are conceptually similar to a math function, where we pass it variables,  
start=0, stop=2*np.pi, num=20

and the function does something and has a result
In math it would be something like f(x, y, z), but in python:  
np.linspace(start=0, stop=2*np.pi, num=20)

But now I want to keep track of the result of that function.
So I assign it to a Variable, in this case called 'x'  
x = np.linspace(start=0, stop=2*np.pi, num=20)

from now on, any time I use x it is the result of that function (unless I redefine x)
How did I know what variables a function accepts and what it does?
Lets take a look at documentation:
np.linspace()
or:
End of explanation
"""


