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
produces the plot shown in the following figure.
The plot for 1 appears to be correct--when n
= 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 (when n
= 2) and 8 (when n
= 3). Instead, multiple values are plotted. Use MATLAB debugging features to isolate the problem.
Debugging Example--The Collatz Problem | Using Debugging Features |