Desktop Tools and Development Environment |
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.
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.
Debugging Example--The Collatz Problem | Debugging Process and Features |
© 1994-2005 The MathWorks, Inc.