
6 Editing and Debugging M-Files
Try out collatzplot to see if it w orks correctly. Use a simple input value,
for example, 3, and com pare the re sults to those sho wn 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 C ollatz series is 1, and
contains one integer. B ut for
n =2andn = 3, it is w rong because there should
be only one value plotted for each integer, the number of integers in the
sequence, which the preceding table show s to be 2 (for
n =2)and8(forn
= 3). Instead, multiple values are plotted. Use MATLAB debugging features
to isolate the problem.
6-106
Commentaires sur ces manuels