Hi! I need help with a graph in mathlab.

8 ビュー (過去 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 Center および File ExchangeFit Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by