Sei sulla pagina 1di 8

Leonardo Carrera Facultad de Ingeniera Mecatrnica ESPE Mtodos Numricos 15 de noviembre de 2012

Mtodo iterativo para resolver sistemas de ecuaciones lineales de GaussSeidel

Deber 1. Encontrar las raices del polinomio:


p(x) = x6 + 6x 6

Mtodos Numricos

Por el mtodo de la biseccin Para resolver vemos primero el grco:

Entonces aplicamos nuestro programa en Matlab:


function r=biseccion1(a,b,e,g) %a y b es el intervalo, e es la tolerancia que %deseamos y q es la funcion f=inline(g); %leer la funcion a1=f(a); b1=f(b); d=abs(a-b); while d>e if a1*b1<0 c=(a+b)/2; if a1*f(c)<0 b=c; else a=c; end d=abs(a-b);

Leonardo Carrera

Deber
else end

Mtodos Numricos

disp('no existe la raiz') break

end r=c; disp('La raiz es') % biseccion1(0.1,5,0.00001,'x^6+6*x-6') % La raiz es % % ans = % % 0.9071

2. Hallar mediante el mtodo de Newton las raices reales de la ecuacin:


f (x) = x2 + 10 cos(x)

Por el grco vemos que hay 2 resultados:

Entonces aplicando nuestro programa hecho en Matlab:


function newtonleo syms x;

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

Por el mtodo de Newton


function newtonleo syms x; 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(' ')

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

Por el mtodo de la secante


function secanteleo syms x; xo=input('Ingrese el valor inicial: '); x1=input('Ingrese el valor final: '); tol=input('Ingrese el porcentaje de error: '); f=input('Ingrese la funcin: '); f=inline(f); xra=0; xr=0; i=1; error_aprox=1; error=0; fx1=f(x1); fxo=f(xo); xr=x1-((x1-xo)/(fx1-fxo))*fx1;

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

Potrebbero piacerti anche