Hi! I need help with a graph in mathlab.

조회 수: 6 (최근 30일)
Anthony Fuentes
Anthony Fuentes 2016년 10월 14일
댓글: Roche de Guzman 2016년 10월 15일
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

채택된 답변

Roche de Guzman
Roche de Guzman 2016년 10월 14일
%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
Anthony Fuentes
Anthony Fuentes 2016년 10월 14일
Oh, thanks a lot friend!
Roche de Guzman
Roche de Guzman 2016년 10월 15일
No problemo :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by