Git and recovering from a mistakeYou will do this problem in the Jupyter notebook so I can see your output. Once again, you will work with your playground repository.
NOTE: At the beginning of each cell, you MUST type %%bash. If you don't do that then you will not be able to work with the necessary bash commands.
Follow the following steps for this problem:
cd /tmp to enter the temporary directoryplayground directory (cd /tmp/playground)git pull origin mybranch1lsplayground directory (cd /tmp/playground)git statusplayground directory (cd /tmp/playground)git reset --hard origin/masterlsplayground directory (cd /tmp/playground)git statusThe whole point of this problem was to show you how to get your local repo back to an earlier state. In this exercise, you accidentally merged something to master that you didn't want. Rather than starting to delete things all over the place, you can simply reset your HEAD to a previous commit.
In [15]:
%%bash
cd /tmp
rm -rf playground
git clone https://github.com/crystalzhaizhai/playground.git
In [16]:
%%bash
cd /tmp/playground
git pull origin mybranch1
ls
In [20]:
%%bash
cd /tmp/playground
git status
In [21]:
%%bash
cd /tmp/playground
git reset --hard origin/master
ls
In [22]:
%%bash
cd /tmp/playground
git status
Git and checking out a single fileSometimes you don't want to merge an entire branch from the upstream but just one file from it. There is a direct use case for such a situation. Suppose I've made an error in this homework (or a lecture) and want to correct it. I fix the mistake in the upstream repo. In the meantime you have edited some other files and you really don't want to manually ignore my older copies of those files. Rather, you want to fix just one file from this new branch. This is how you do it.
As usual, be sure to type in %%bash before you write any bash commands in a cell.
Note: The steps below assume that you have already cloned the playground repo in this notebook.
playground repo and fetch the changes from the master branch of the course remote.git checkout course/master -- README.md. The -- means that README.md is a file (as opposed to a branch).cat README.md. This just looks at the updated file.git statusgit status
In [27]:
%%bash
cd /tmp/playground
cat .git/config
In [31]:
%%bash
cd /tmp/playground
git remote add course https://github.com/IACS-CS-207/playground.git
cat .git/config
In [32]:
%%bash
cd /tmp/playground
git fetch course master
In [35]:
%%bash
cd /tmp/playground
git checkout course/master -- README.md
cat README.md
In [90]:
%%bash
cd /tmp/playground
git add .
git commit -m "playgroundchange" -a
git status
git push
This problem is related to the Lecture 4 exercises.
languages.txt file. This file contains all the languages that students listed as their primary language in the course survey.Counter method from the collections library to count the number of occurrences of each element of the list.most_common() method here.%matplotlib inline at the beginning of your notebook.import matplotlib.pyplot as plt.plt.bar(x_coords, freqs). You need to define x_coords and freqs.numpy arange function to create x_coords. Remember, x_coords is the x-axis and it should have points for each distinct language.freqs, you may want to use the values() method on your result from step 3. That is, freqs = result_from_3.values().plt.xticks(x_coords, labels) where labels can be accessed through the keys() method on your result from step 3.
In [50]:
with open("../../lectures/L4/languages.txt","r") as f:
primary_course=f.read().split()
from collections import Counter
course_count=Counter(primary_course)
In [57]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x_coords=np.arange(len(course_count))
total=np.sum(course_count.values())
freqs=course_count.values()
plt.xticks(x_coords,course_count.keys())
plt.bar(x_coords,freqs)
Out[57]:
In chemical kinetics, the reaction rate coefficient for a given reaction depends on the temperature of the system. The functional relationship between the reaction rate coefficient and temperature is given by the Arrhenius rate: \begin{align} k\left(T\right) = A T^{b}\exp\left(-\frac{E}{RT}\right) \end{align} where $A$, $b$, and $E$ are parameters, $R = 8.314 \dfrac{\textrm{J}}{\textrm{mol} \textrm{ K}}$ is the universal gas constant, and $T$ is the temperature.
Write a function which returns $k\left(T\right)$ given $A$, $b$, $E$, and $T$. Here are a few requirements:
In [3]:
def kinetics(p,T, R=8.314):
import numpy as np
if len(p)<3:
print("Error! Less than 3 parameters")
return()
try:
k=p[0]*(T**p[1])*np.exp(-p[2]/(R*T))
return k
except ZeroDivisionError:
print("Error! Divided by 0")
return()
In [4]:
kinetics([1,2],0)
Out[4]:
Using numpy arrays, plot $k\left(T\right)$ for $T\in\left(0, 5000\right]$ for three different sets of parameters $\left\{A, b, E\right\}$. Make sure all three lines are on the same figure and be sure to label each line. You may use the function from Problem 2. You may want to play with the parameters a little bit to get some nice curves but you won't lose points for ugly curves either (as long as they're correct!).
In [113]:
TT=np.arange(1,5000)
plt.plot(TT,kinetics([3,6,2],TT),'r')
plt.plot(TT,kinetics([4,5,6],TT),'g')
plt.plot(TT,kinetics([6,5,4],TT),'b')
plt.legend(["A,b,E=[3,6,2]","A,b,E=[4,5,6]","A,b,E=[6,5,4]"])
plt.xlabel("T")
plt.ylabel("k")
plt.title("kinetics")
Out[113]:
In [110]:
%%bash
git add "HW3_final.ipynb"
git commit -m "HW3" -a
git status
git remote
git push origin master
In [ ]: