I am trying to do the Collatz problem on Matlab. I am having trouble plotting my results.
a = input( 'Please enter a value for a:');
b = input( 'Please enter a value for b:');
for n = (a:b),
count = 0;
while n > 1
count= count+ 1;
if mod(n,2) == 0
n = n/2;
else
n = (3*n+1);
end
plot (n:count);
end
end
I am attempting to plot the values of n and count (the length of the sequence of n) between two user inputted numbers inclusive (eg from 1 to 40). My graph comes out as a line y = x instead of the intended solution.
Thanks for the help
noobcodes