BtM 2018, Week 11

Hi BtM students – week 11 is here! Our topic is errors, bugs, mistakes: How to find them in your code, and how to avoid them.

The slides are here. And the sample code we played with in class is here.

As for this week’s lab, it consists in finding 10 errors in a pice of MATLAB code, and answering one question. The code file is here. It calculates Fibonacci numbers, and the ratio of successive numbers, which converge towards the golden ratio (1.61803…). The intended output is this plot:

As for your task:

  • Make a clean (untouched) copy of your code file first, before working on it. The code won’t even run until you’ve found and corrected the syntax and runtime errors.
  • There are 10 errors in it. For each, you need to provide the line, the error message (if there is one) and the type (syntax error, runtime error or logical error).
  • Look at the help MATLAB gives you – red and orange bars at the right edge.
  • In addition to the debugging, you are also to use the debugger to find out the value of the variable ii on the second iteration of the for-loop. For this, you need to set a break point at the beginning of the loop, and then use the “step” button to proceed step-by-step. Keep an eye in how ii changes. The second value of ii is what you are asked to find. Before tackling this task, you’ll have to have found the first two errors, otherwise you can’t run the loop! (If you still have trouble, you can, in a copy of the file, delete or comment out what comes after the loop so that errors in this part don’t prevent you from running it.)