- /
-
Visualizing 3x+1 Problem
on 28 Nov 2023
- 14
- 20
- 0
- 0
- 354
drawframe(1);
Write your drawframe function below
function drawframe(f)
count = 1;
x = zeros(1e6,1);
x(count) = f;
r = rem(x(count),2);
if(r==1)
x(count+1) = 3*x(count)+1;
r = rem(x(count+1),2);
count = count +1;
end
while x(count)~= 1
if r==0
x(count+1) = x(count)/2;
r = rem(x(count+1),2);
else
x(count+1) = 3*x(count)+1;
r = rem(x(count+1),2);
end
count = count +1;
end
% disp(x);
x = resize(x,[count 1]);
plot(x, 'Marker','o','LineStyle','-', 'LineWidth',1);hold on
end