| 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 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 length of the sequences, which the preceding table shows to be 2 and 8 respectively. Instead, multiple values are plotted. Use MATLAB debugging features to isolate the problem.
| Debugging Example - The Collatz Problem | Using Debugging Features | ![]() |