sec ante

4
%newton rapshon xf(1)=input('Ingrese el valor inicial: '); tol=input('Ingrese el porcentaje de error: '); f=input('Ingrese la función: '); hold on; g=input('Ingrese la función f(x), despejada g(f(x)): '); z=x; hold on; %graficamos la funcion ezplot(f); ezplot(z); grid on; xf(2)=input('Ingrese el intervalo inferior: '); xf(3)=input('Ingrese el intervalo superior: '); i=1; fx(i)=xf(1); f1=subs(f,x,fx(i)); z=diff(f); d=subs(z,x,fx(i)); syms x; ea(1)=100; while abs(ea(i))>=tol; fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1)); ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100); i=i+1; end fprintf('\n\nNEWTON RAPSHON:\n'); fprintf('i fx(i) Error aprox (i) \n'); for j=1:i; fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j)); end i=i+1; fprintf('\n\nNumero de iteraciones: %d \n',i-1); %PUNTO FIJO syms x; i=1; while abs(ea(i))>=tol, xf(i+1) = subs(g,x,xf(i)); ea(i+1) = abs((xf(i+1)-xf(i))/xf(i+1))*100; i=i+1; end fprintf('\n\nPUNTO FIJO:\n'); fprintf('i xf(i) Error aprox (i) \n'); for j=1:i; fprintf('%2d \t %11.7f \t %11.7f \n',j-1,xf(j),ea(j)); end i=i+1; fprintf('\n\nNumero de iteraciones: %d \n' ,i-1);

Upload: karen-giannella-apaza

Post on 18-Dec-2015

214 views

Category:

Documents


0 download

DESCRIPTION

secante

TRANSCRIPT

%newton rapshon xf(1)=input('Ingrese el valor inicial: ');tol=input('Ingrese el porcentaje de error: ');f=input('Ingrese la funcin: ');hold on;g=input('Ingrese la funcin f(x), despejada g(f(x)): ');z=x;hold on;%graficamos la funcion ezplot(f);ezplot(z);grid on;xf(2)=input('Ingrese el intervalo inferior: ');xf(3)=input('Ingrese el intervalo superior: ');i=1;fx(i)=xf(1);f1=subs(f,x,fx(i));z=diff(f);d=subs(z,x,fx(i));syms x;ea(1)=100;while abs(ea(i))>=tol; fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1)); ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100); i=i+1;endfprintf('\n\nNEWTON RAPSHON:\n');fprintf('i fx(i) Error aprox (i) \n');for j=1:i; fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));endi=i+1;fprintf('\n\nNumero de iteraciones: %d \n',i-1); %PUNTO FIJO syms x;i=1;while abs(ea(i))>=tol, xf(i+1) = subs(g,x,xf(i)); ea(i+1) = abs((xf(i+1)-xf(i))/xf(i+1))*100; i=i+1;endfprintf('\n\nPUNTO FIJO:\n');fprintf('i xf(i) Error aprox (i) \n');for j=1:i;fprintf('%2d \t %11.7f \t %11.7f \n',j-1,xf(j),ea(j));endi=i+1;fprintf('\n\nNumero de iteraciones: %d \n' ,i-1); %SECANTE syms x;f1=subs(f,x,xf(2));f2=subs(f,x,xf(3));i=1;j=2; while abs(ea(i))>=tol xf(j+1)=(xf(j-1)*f2-xf(j)*f1)/(f2-f1); f1=f2; f2=subs(f,x,xf(j+1)); ea(i+1)=(xf(j+1)-xf(j))/xf(j+1)*100; j=j+1; i=i+1; end fprintf('\n\nSECANTE:\n'); fprintf(' i xf(i) Error aprox (i) \n'); %fprintf('%2d\t%11.7f\t\n',0,x(1)); for k=2:j; fprintf('%2d\t%11.7f\t%11.7f\n',k-2,xf(k),ea(k-1)); end fprintf('\n\nNumero de iteraciones: %d \n',i); EJEMPLO

Ingrese el valor inicial: 0Ingrese el porcentaje de error: 0.0001Ingrese la funcin: ((3*(x^2))-(2.718281^x))Ingrese la funcin f(x), despejada g(f(x)): ((3*(x^2))-(2.718281^x))+xIngrese la funcin z: xIngrese el intervalo inferior: -2Ingrese el intervalo superior: 0

NEWTON RAPSHON:i fx(i) Error aprox (i) 0 0.0000000 100.000 1 -1.0000003 100.000 2 -0.5866568 70.457 3 -0.4698020 24.873 4 -0.4590539 2.341 5 -0.4589623 0.020 6 -0.4589623 0.000

Numero de iteraciones: 7

PUNTO FIJO:i xf(i) Error aprox (i) 0 0.0000000 100.0000000 1 -1.0000000 100.0000000 2 1.6321204 161.2699879 3 4.5088658 63.8019729 4 -25.3201475 117.8074229 5 1898.0094616 101.3340369 6 -Inf NaN

Numero de iteraciones: 7

SECANTE: i xf(i) Error aprox (i) 0 -1.0000000100.0000000 1 10.7598240109.2938323 2 -0.99927631176.7616579 3 -0.9986153 -0.0661882 4 -0.5862714-70.3332901 5 -0.4951603-18.4003122 6 -0.4622145 -7.1278214 7 -0.4590529 -0.6887190 8 -0.4589625 -0.0196960 9 -0.4589623 -0.0000508

Numero de iteraciones: 10