Code covered by the BSD License  

Highlights from
Collatz and Goldbach Conjucture

image thumbnail

Collatz and Goldbach Conjucture

by

 

Verification of Collatz and Goldbach Conjucture

collatz_conjucture.m
%collatz conjucture verification
clc
clear
n = input('enter any +ve number = ');
if n < 0
    disp(' ')
    disp('plz enter +ve number')
    return
end
k = 1;
z(1,k) = n;
while z(1,k)>1
    if (rem(z(1,k),2)==0)
        z(1,k+1) = z(1,k)/2;
    else
        z(k+1) = 3*z(1,k) + 1;
    end
    k = k+1;
    drawnow
    plot(1:length(z),z,'-*','linewidth',2,'markeredgecolor','r')
    grid on
    pause(0.1)
end
disp(' ')
%disp(z)
disp(' ')
fprintf('the last number of the collatz series\nwith number %d is\nalways %d\n',n,z(length(z)))
%plot(1:length(z),z,'-*','linewidth',2,'markeredgecolor','r')
%grid on
clear k n

Contact us