This notebook contains material for CBE 20258 Numerical and Statistical Analysis taught at the University of Notre Dame. (c) Professors Alexander Dowling, Ryan McClarren, and Yamil Colón. This collection of notebooks cbe-xx258 is available on Github.

1.1 Welcome to Jupyter Notebooks and Vocareum

1.1.1 Quick Python Introduction

1.1.1.1 Variables

In Python, variables do not need to be declared before they are used. In other words, Python automatically decided on the correct variable type (integer, float, etc.) You can simply define a new variable using x = 5. This is just like MATLAB.

Home Activity: In the cell below, assign the value of 5 to the variable x. Then type Shift+Enter to execute the line.
In [ ]:
 

We can see the value of the variable using the built-in print function. For example, to print the value of x, we would use print(x).

Home Activity: Print the value of x. Type Shift+Enter to execute the cell. (We'll stop reminding you to do this moving forward.)
In [ ]:
 
Home Activity: Now change the value of x to 8 and execute the cell.
In [ ]:
 

1.1.1.2 Execution Order

Note: When using Jupyter notebooks, it is very important to know that the cells can be executed out of order (intentionally or not). The state of the environment (e.g., values of variables, imports, etc.) is defined by the execution order.

Home Activity: To see this concept, rerun the cell above with the print statement.

You should see that the value 8 is now printed. This may seem problematic if you are used to programming in environments where the state is linked to the order of the commands as written, not as executed.

Again, notice that the state of the environment is determined by the execution order. Note also that the square brackets to the left of the cell show the order that cells were executed. If you scroll to the top, you should see that the code cells show an execution order of [1] , [2] , [5] , and [4], indicating the actual execution order.

There are some useful menu commands at the top of the Jupyter notebook to help with these problems and make sure you retain the execution order as expected.

Some important commands to remember:

  • You can clear the current state with the menu item Kernel | Restart & Clear Output
  • It is often useful to clear the state using the menu command just described, and then execute all the lines above the currently selected cell using Cell | Run All Above .
  • You can clear all the state and re-run the entire notebook using Kernel | Restart & Run All.

1.1.2 Vocareum Autograder

Note: The autograder is NOT supported on Colab. All of the autograder tests and solutions have been stripped out of these notebooks.

We will use the autograder in Vocareum for homework assignments, which gives you instant feedback on your work. The autograder is confirmed to allow for unlimited submissions. You just need to wait 5 minutes between submissions.

It is very important carefully read the assignment instructions. The autograder is simply executing logical checks behind the scenes. For example, if the assignment instructions say to store your final answer in the variable final_ans but you instead write my_ans, the autograder will mark it as wrong.

Our First Autograded Submission

We want to store the first seven elements of the Fibonaci sequence in the list fib. Below is an answer with a few mistakes:

In [ ]:
# YOUR SOLUTION HERE

fibs = [0, -1, 1, 2, 4, 5, 9, 13]
In [ ]:
 
In [ ]:
 
Home Activity: Submit this solution and look at the feedback from the autograder.
Home Activity: Fix the mistakes. You are done when all of the grading tests pass.

1.1.3 Gradescope

The autograde in Vocareum is nice for (near) instant feedback. But we'll also use Gradescope throughout the semester to collect assignments that require "pencil and paper" analysis or written discussion.

1.1.3.1 Handwritten Work

We'll occassionally ask you to submit handwritten work (e.g., mathematical models, pseudocode) via Gradescope. Here are the instructions:

  1. Scan/photograph your work and convert to a single PDF. “Scanbot” (Android & iOS), “CamScanner” (Android & iOS) and “Scannable” (iOS) are great phone apps with free versions. There are also document scanners in the library. See the syllabus for more information.
  2. Upload the single PDF to Gradescope.
  3. Mark the sections as requested in Gradescope.

1.1.3.2 Notebooks

In [ ]: