%EJEMPLO DE ALGORITMO INESTABLE!! %ELABORADO POR PROF. MARLLINY MONSALVE close all clear all clc %====================================== %SECUENCIA QUE "CALCULA" EL AREA BAJO LA CURVA n = 60; y(1) = log(6)-log(5); %Valor inicial for i=1:n; y(i+1) = (1/i)-5*y(i); %#ok end %====================================== n=[1 4 8 12 24 48 60]; tn = length(n); X = 0:1e-4:1; figure('Position',[300,300,650,550],'Name','ALGORITMO INESTABLE'); title('Grafica para f(x) = x^n/(x+5) en [0,1]','FontSize',13) hold on %GRAFICAS PARA VER EL AREA BAJO LA CURVA pos=0.11; for k=1:tn Y= (X.^n(k))./(X+5); h = plot(X,Y); col = [rand rand rand]; set(h,'LineWidth',2,'color',col); etqs(1,k)=cellstr(strcat('n = ',num2str(n(k)))); %#ok legend('String',etqs); legend('Location','BestOutside'); text(0.4,0.17,... ['Observe al area bajo la curva'],... 'HorizontalAlignment','center',... 'BackgroundColor',col,... 'Margin',10); pos=pos - 0.01; text(1.01,pos,['y_{',num2str(n(k)),'}','= ',num2str(y(n(k)),'%0.5g')],'Margin',10); disp('ENTER para continuar') pause end text(0.4,0.15,... ['SIEMPRE DISMINUYE!!'],... 'HorizontalAlignment','center',... 'BackgroundColor',[0.5 0.5 0.9],... 'Margin',10,'FontSize',11); text(1.2,0.03,... ['PERO y_n AUMENTA'],... 'HorizontalAlignment','center',... 'BackgroundColor',[0.5 0.5 0.9],... 'FontSize',11);