In [ ]:
import matplotlib.pyplot as plt
import numpy as np
from nose.tools import assert_equal
import sys

Module 1 Assignment

A few things you should keep in mind when working on assignments:

  1. Make sure you fill in any place that says YOUR CODE HERE. Do not write your answer anywhere else other than where it says YOUR CODE HERE. Anything you write elsewhere will be removed or overwritten by the autograder.

  2. Before you submit your assignment, make sure everything runs as expected. Go to the menubar, select Kernel, and restart the kernel and run all cells (Restart & Run all).

  3. Do not change the title (i.e. file name) of this notebook.

  4. Make sure that you save your work (in the menubar, select FileSave and CheckPoint).


Problem 1: Using Markdown

In this problem you will practice using Markdown in a Jupyter Notebook.

Change the cell below to Markdown format and run the cell.

In [ ]:
This cell is in markdown format

Problem 2: Showing a plot

In the cell below we would like to show a plot, but the cell magic to show the plot in the notebook is missing.

Add the matplotlib magic to the cell below so that the plot is shown.

In [ ]:
### YOUR CODE HERE
In [ ]:
theta = np.arange(0., np.pi, 0.01)
y = np.cos(theta)

plt.plot(theta, y)
plt.xlabel(r"$\theta$")
plt.ylabel(r"$\cos$($\theta$)")
plt.title(r"Plot of $\cos$($\theta$)")
plt.show()

Problem 3: Importing Modules

In order to do mathematical operations, we will first need to import the math module. Use the cell below to import the math module.

In [ ]:
### YOUR CODE HERE
In [ ]:
if 'math' in sys.modules:
    print('math module has been successfully imported')

Problem 4: Cubing a number

Calculate $10^{3}$ and save it in a variable called "cubed"

In [ ]:
### YOUR CODE HERE
In [ ]:
assert_equal(cubed, 1000)

Problem 5: Basic Mathematical Operations

In this problem write the following code corresponding to this equation: $y = (\sqrt{9}*8)^{2}$

Store the result of this function in a variable named y.

In [ ]:
### YOUR CODE HERE
In [ ]:
assert_equal(y, 576)

Problem 6: Calling Functions

In this problem you will:

  • Call the sqrt function in Python's math library and pass in the number 9. Store the result in a variable called a.
  • Call the abs function and pass in the number -25. Store the result in a variable called b
In [ ]:
### YOUR CODE HERE
In [ ]:
assert_equal(a, 3)
assert_equal(b, 25)

© 2017: Robert J. Brunner at the University of Illinois.

This notebook is released under the Creative Commons license CC BY-NC-SA 4.0. Any reproduction, adaptation, distribution, dissemination or making available of this notebook for commercial use is not allowed unless authorized in writing by the copyright holder.