Hi! I need help with a graph in mathlab.
    8 views (last 30 days)
  
       Show older comments
    
    Anthony Fuentes
 on 14 Oct 2016
  
    
    
    
    
    Commented: Roche de Guzman
      
 on 15 Oct 2016
            I did a program that is about the Collatz Conjecture, and I did two graphs, but the problem is that when I put both in the same figure, the two graphs appears in the same side, one over the other, and appears like a spring, very small. Thanks for your help. I put the program below. And the Graphs like a attach file. Thanks a lot!
%
%Programa que calcula la secuencia de Collatz con un número dado
%
clc, clear, close all
disp('=========================================================================================')
disp('==================================COLLATZ SEQUENCE======================================')
disp('=========================================================================================')
disp(' ')
disp(' Definicion: un número natural es aquél que usamos para contar')
disp('NO entre el cero, numeros complejos, numeros irracionales (fraccionarios/decimales) ó negativos')
disp(' ')
n=input('entre el número natural:   ');
seq=zeros(1, n);
seq(1) = n;
i = 2; 
while seq(i-1) ~= 1
    if mod(seq(i-1), 2) == 0
        seq(i) = seq(i-1)/2;
    else
        seq(i) = 3*seq(i-1) + 1;
    end
    i = i+1;
end
p = length(seq);
%Gráfica #1
figure;
subplot(n, 1, 1);
plot(seq,'-m*','LineWidth',2,'MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5, 'Marker', 'diamond')
xlabel(['Términos: ',int2str(i-1)])
title(['Secuencia de Collatz ( n = ' num2str(n),' )'], 'FontSize',12) 
ylim([0 100]);  
xlim([ 0 30]); 
grid on 
subplot(n,1, 2)
semilogy(seq, '-m*', 'LineWidth',2,'MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5, 'Marker', 'diamond')
xlabel(['Términos: ',int2str(i-1)])
title(['Secuencia de Collatz ( n = ' num2str(n),' )'], 'FontSize',12) 
ylim([0 100]);  
xlim([ 0 30]); 
grid on
0 Comments
Accepted Answer
  Roche de Guzman
      
 on 14 Oct 2016
        %Programa que calcula la secuencia de Collatz con un número dado % 
clc; clear; close all;
disp('=========================================================================================');
disp('==================================COLLATZ SEQUENCE======================================');
disp('=========================================================================================');
disp(' ');
disp(' Definicion: un número natural es aquél que usamos para contar');
disp(' NO entre el cero, numeros complejos, numeros irracionales (fraccionarios/decimales) ó negativos');
disp(' ');
n=input('entre el número natural: ');
seq=zeros(1, n);
seq(1) = n;
i = 2;
while seq(i-1) ~= 1
    if mod(seq(i-1), 2) == 0 
        seq(i) = seq(i-1)/2; 
    else seq(i) = 3*seq(i-1) + 1; 
    end
    i = i+1; 
end
p = length(seq); 
%Gráfica #1 figure;
subplot(2, 1, 1); 
plot(seq,'-m*','LineWidth',2,'MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5, 'Marker', 'diamond'); 
xlabel(['Términos: ',int2str(i-1)]);
title(['Secuencia de Collatz ( n = ' num2str(n),' )'], 'FontSize',12);
grid on;
subplot(2,1, 2);
semilogy(seq, '-m*', 'LineWidth',2,'MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',5, 'Marker', 'diamond');
xlabel(['Términos: ',int2str(i-1)]);
title(['Secuencia de Collatz ( n = ' num2str(n),' )'], 'FontSize',12);
grid on;
2 Comments
More Answers (0)
See Also
Categories
				Find more on Fit Postprocessing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
