SUNY Geneseo Department of Computer Science


Lesson 10—Matlab’s Debugger

CSci 120, Spring 2014

Prof. Doug Baldwin

Complete by Monday, April 14
or Wednesday, April 16

Purpose

This lesson introduces you to some of the features of Matlab’s debugger.

Background

A debugger is a software tool that helps you watch in detail how a program executes, typically in order to find and fix mistakes in it. Matlab has a rather nice debugger, although it isn’t immediately obvious how to use it. This lesson introduces you to its basic use.

To learn about techniques for debugging programs, and how Matlab’s debugger supports them, read and watch the following:

Exercise

I have written a Matlab function named badLog10 that is supposed to compute the base 10 logarithm of its argument. However, as the name suggests, its answers are egregiously wrong. Your job is to use Matlab’s debugger to find and fix the error(s) in badLog10.

As an example of what “badLog10” actually does and should do, suppose I type

badLog10( 100 )

into Matlab’s command window. Because the base 10 logarithm of 100 is 2 (i.e., 102 = 100), the function should return 2. However, as given to you, it in fact returns 100. Comments in the “badLog10.m” file describe some other example inputs and the values they should produce. You can devise other examples for yourself and find the correct answers with a calculator or Matlab’s own log10 function.

As suggested above, my badLog10 function is available in a file named “badLog10.m” You can download a copy of this file from our “Exercises” web page (or just click on the file name above).

At its heart, badLog10 uses the bisection method to find a number r such that x - 10r = 0, where x is the argument to badLog10. The resulting value of r is then the logarithm of x. This idea is a reasonably good one; the problem in badLog10 is just a flawed implementation of it. See comments in “badLog10.m” for more information about how badLog10 is supposed to work.

Follow-Up

In your study group’s first meeting with me following your “Complete By” date above, we will talk about how you used the debugger to find errors in badLog10 and how you fixed them. I may also ask you to show me the corrected function, or to demonstrate things you did with the debugger. Please bring at least one copy of the necessary “.m” file(s) to your meeting. This will speed the meeting along.