Hi! I need help with a graph in mathlab.

10 vues (au cours des 30 derniers jours)
Anthony Fuentes
Anthony Fuentes le 14 Oct 2016
Commenté : Roche de Guzman le 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

Réponse acceptée

Roche de Guzman
Roche de Guzman le 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 commentaires
Anthony Fuentes
Anthony Fuentes le 14 Oct 2016
Oh, thanks a lot friend!
Roche de Guzman
Roche de Guzman le 15 Oct 2016
No problemo :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by