Desktop Tools and Development Environment Previous page   Next Page

Trial Run for Example

Try out collatzplot to see if it works correctly. Use a simple input value, for example, 3, and compare the results to those shown in the preceding table. Typing

collatzplot(3)

produces the plot shown in the following figure.

Image of plot. Ther is one point at x = 1, two points at x = 2, and 8 points at x = 3.

The plot for n = 1 appears to be correct--for 1, the Collatz series is 1, and contains one integer. But for n = 2 and n = 3, it is wrong because there should be only one value plotted for each integer, the number of integers in the sequence, which the preceding table shows to be 2 (for n = 2) and 8 (for n = 3). Instead, multiple values are plotted. Use MATLAB debugging features to isolate the problem.


Previous page  Debugging Example--The Collatz Problem Debugging Process and Features Next page

© 1994-2005 The MathWorks, Inc.