Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Mtodos Numricos
Leonardo Carrera
Deber
else end
Mtodos Numricos
Leonardo Carrera
Deber
Mtodos Numricos
xo=input('Ingrese el valor inicial: '); tol=input('Ingrese el porcentaje de error: '); f=input('Ingrese la funcin: '); i=1; fx(i)=xo; f1=subs(f,x,fx(i)); z=diff(f); d=subs(z,x,fx(i)); 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 disp(' ') disp('Resultado') disp(fx(i)) disp('iteraciones hasta alcanzar a tolerancia: ') disp(i) %fprintf('i fx(i) Error aprox (i) \n'); disp(' ') disp('iteraciones resultados %error') disp(' ') for j=1:i; fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j)); end %Primer Valor % Ingrese el valor inicial: 50 % Ingrese el porcentaje de error: 0.1 % Ingrese la funcin: x.^2+10*cos(x) %
Leonardo Carrera
Deber
Mtodos Numricos
% Resultado % -1.9689 % % iteraciones hasta alcanzar a tolerancia: % 8 % % iteraciones resultados %error % % 0 50.0000000 100.000 % 1 25.5451375 95.732 % 2 11.4906658 122.312 % 3 7.1865749 59.891 % 4 -1.6855913 526.353 % 5 -1.9439774 13.292 % 6 -1.9685460 1.248 % 7 -1.9688729 0.017 % %Segundo Valor % Ingrese el valor inicial: 100 % Ingrese el porcentaje de error: 0.1 % Ingrese la funcin: x.^2+10*cos(x) % % Resultado % 3.1620 % % iteraciones hasta alcanzar a tolerancia: % 7 % % iteraciones resultados %error % % 0 100.0000000 100.000 % 1 51.1926035 95.341 % 2 23.3635078 119.114 % 3 13.7425159 70.009 % 4 3.1856780 331.384 % 5 3.1624456 0.735 % 6 3.1619503 0.016
Leonardo Carrera
Deber
Mtodos Numricos
3. Calcular por los mtodos de Newton y Secante, la raiz de la siguiente ecuacin no lineal:
f (x) = x2 2xex + e2x
Leonardo Carrera
Deber
Mtodos Numricos
disp('iteraciones resultados %error') disp(' ') for j=1:i; fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j)); end % % % % % % % % % % newtonleo Ingrese el valor inicial: -10 Ingrese el porcentaje de error: 0.01 Ingrese la funcin: x^2-2*x*exp(-x)+exp(-2*x) Resultado 0.5671 iteraciones hasta alcanzar a tolerancia: 35
Leonardo Carrera
Deber
Mtodos Numricos
disp(' ') fprintf('It. X0 X1 Xr Error aprox \n') fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \t %11.7f \n',i,xo,x1,xr,error);
while error_aprox >= tol; xra=xr; x1=xr; fx1=f(x1); fxo=f(xo); xr=x1-((x1-xo)/(fx1-fxo))*fx1; error = abs((xr - xra) / xr); error_aprox = error; i=i+1; xo=x1; fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \t %11.7f \n',i,xo,x1,xr,error_apr end end % % % % % % Ingrese el valor inicial: -10 Ingrese el valor final: -9 Ingrese el porcentaje de error: 0.01 Ingrese la funcin: x^2-2*x*exp(-x)+exp(-2*x) It. X0 X1 Xr(resp) Error aprox 36 0.5552855 0.5552855 0.5598028 0.0080693
Leonardo Carrera