You are on page 1of 7

Mtodo de la bieccion

% Este algoritmo resuelve ecuaciones por el metodo de la biseccion % a y b es el intervalo de la solucin % d y er son los errores a=input('ingrese el lmite inferior a='); b=input('ingrese el lmite superior b='); M=input('numero de iteraciones M='); d=input('d='); er=input('er='); u=f(a); v=f(b); c=b-a; %fprintf('%f\t%f\t%f\t%f\t%f\n',a,b,u,v); if sign(u)==sign(v) disp('esta mal') else for k=1:M e=c/2; c=a+e; w=f(c); fprintf('%d\t%f\t%f\t%f\t%f\t%f\n',k,a,b,c,w,e) if abs(e)<d || abs(w)<er break end if sign(w)~=sign(u) b=c; v=w; else a=c; u=w; end c=b-a; end end c

Mtodo del puinto fijo


% algorimo del metodo de punto fijo x0=input('ingrese un punto de inicio x0='); m=input(' ingrese el numero de iteraciones m='); d=input('ingrese un munero muy pequeo d='); for k=1:m x1=x0; x0=f(x0); fprintf('%d \t %f \t %f \n',k,x1,x0); if abs(x1-x0)<d break; end end x0

METODO DE NEWTON % Este programa halla races con el algoritmo de newton x=input('ingrese el punto inicial x='); m=input('ingrese el numero de iteraciones m='); df=input('df='); y=f(x); e=input('ingrese un numero pequeo e='); fprintf('%d\t%f\t%f\n',0,x,y) for k=1:m x=x-y/df; y=f(x); fprintf('%d\t%f\t%f\n',k,x,y) if abs(y)<e break end end

METODO DE LA SECANTE % Este algoritmo halla las races de las ecuaciones por el mtodo de la secante a=input('ingrese el primer punto de inicio a ='); b=input('ingrese el segundo punto b ='); m=input('ingrese el numero de iteraciones m ='); d=input('ingrese un numero muy pequeo d ='); e=input('ingrese un numero muy pequeo e ='); u=f(a); v=f(b); fprintf('%f\t% f\t%f\n',0,a,u) fprintf('%f\t%f\t%f\n',1,b,v) for k=1:m if abs(u)<abs(v) s=b; b=a; a=s; p=v; v=u; u=p; end s=(b-a)/(v-u); a=b; u=v; b=b-(v*s); v=f(b); fprintf('%f\t%f\t%f\n',k,b,v) if abs(v)<e || abs(b-a)<d break end end b

A.- El de sustitucin progresiva y sustitucin regresiva para sistemas triangulares PROGRESIVA


%Este algoritmo resuelve sistemas triangulares inferiores %metodo empleado SUSTITUCION PROGRESIVA clear A=input('ingrese la matriz A ='); b=input('ingrese la matriz b ='); n=length(A); x=zeros(n); d=n; for d=1:n m=0; for i=1:n

REGRESIVA
%Esten algritmo resulve sistemas triangulares superiores %Metodo empleado SUSTITUCION REGRESIVA A=input('ingrese la matriz A='); b=input('ingrese la matriz b='); n=length(b); x=zeros(n); d=n; while d>=1 m=0; for i=d:n m=m+A(d,i)*x(i);

m=m+A(d,i)*x(i); end x(d)=(b(d)-m)/A(d,d); end x(1:i)'

end x(d)=(b(d)-m)/A(d,d); d=d-1; end x(1:i)'

B.- El de eliminacin de Gauss simple y el de eliminacin de Gauss con filas permutadas GAUUS SIMPLE GAUS CON FLAS PERMUTADAS
%Este algoritmpo resulve sistemas de ecuaciones %Usando el metodo de GAUSS BASICO A=input('ingrese la matriz A ='); n=length(A); b=input('ingrese la atriz b='); for k=1:n-1 for i=k+1:n z=A(i,k)/A(k,k); A(i,k)=0; for j=k+1:n A(i,j)=A(i,j)-z*A(k,j); end b(i)=b(i)-z*b(k); end end disp('nueva A');disp(A); disp('nueva b');disp(b); f=length(A); d=f; x=zeros(f); while d>=1 v=0; for i=d:f v=v+A(d,i)*x(i); end x(d)=(b(d)-v)/A(d,d); d=d-1; end x(1:i)' %GAUSS CON FILAS PERMUTADAS A=input('inrese la matriz A='); b=input('inrese la matriz b='); p=input('orden de permutacio de las filas p='); n=length(A); for k=i:n-1 for i=k+1:n z=A(p(i),k)/A(p(k),k); A(p(i),k)=0; for m=k+1:n A(p(i),m)=A(p(i),m)z*A(p(k),m); end b(p(i))=b(p(i)-z*b(p(k))); end end for w=1:n F(n,:)=A(p(n),:); bb(n)=b(p(n)); end disp('la nuea matriz');disp(F);disp('la nueva igualdad');disp(bb); n=length(A); k=n;x=zeros(n); while k>=1 m=0; for i=k:n m=m+F(k,i)*x(i); end x(k)=(bb(k)-m)/F(k,k); k=k-1; end x(1:i)'

c.- El de eliminacioinde gauus con pivoteo de filas escaladas


%ELIMINACION DE GAUSS CON FILAS ESCALADAS clear A=input('ingrese la matiz A='); b=input('ingrese la matiz b='); n=length(A); for i=1:n p(i)=i; s(i)=max(abs(A(i,:)));

end for k=1:n-1 for j=k:n if abs(A(p(j),k))/s(p(j))>=abs(A(p(k),k))/s(p(k)) a=p(k); p(k)=p(j); p(j)=a; end end for i=k+1:n z=A(p(i),k)/A(p(k),k); A(p(i),k)=z; for j=k+1:n A(p(i),j)=A(p(i),j)-z*A(p(k),j); end end end for i=1:n u(i,:)=A(p(i),:); bb(i)=b(p(i)); end disp('La nueva matriz es'); disp(u); for i=1:n-1 for j=i+1:n bb(j)=bb(j)-bb(i)*u(j,i); end end disp('La neva matriz b es'); disp(bb); r=length(u); k=r; x=zeros(r); while k>=1 a=0; for c=k:r a=a+u(k,c)*x(c); end x(k)=(bb(k)-a)/u(k,k); k=k-1; end s=x(:,1); disp('Las solucioies son'); disp(s);

D.- Los mtodos iterativos de Richarsom, Jacobi y Gauss seidel METODO DE RICHARSON %metodo de richarsom clear A=input('ingrese la matriz A='); b=input('ingrese la matriz b='); x=input('ingrese los puntos iniciales x='); M=input('ingrese el numero de iteraciones M='); n=length(A); for k=1:M for i=1:n r(i)= b(i)-(A(i,1:n)*x(1:n)); end

for i=1:n x(i)=x(i)+r(i); end fprintf('%d\t%f\t%f\t%f\t%f\t%f\t%f\n',k,x') end

METODO DE JACOBI
%metodo de jacobi %La matriz A debe de ser diagonalmente dominante A=input('ingrese la matriz A='); b=input('ingrese la matriz b='); x=input('ingrese los puntos iniciales x='); M=input('ingrese el numero de iteraciones M='); n=length(A); Z=0; for k=1:M for i=1:n p=0; for j=1:n m=A(i,j)*x(j); if j==i m=0; end p=p+m; end u(i)=(b(i)-p)/A(i,i); end for i=1:n x(i)=u(i); end if max(abs(x-Z))<0.000001 break; end v(:,k)=x; z=x; fprintf('%d\t%f\t',k,x); fprintf('\n'); end

METODO DE GAUSS-SEIDEL
%gauss seidel clear A=input('ingrese la matriz A='); b=input('ingrese la matriz b='); x=input('ingrese los puntos iniciales x='); M=input('ingrese el numero de iteraciones M='); n=length(A); z=0; for k=1:M for i=1:n p=0; for j=i:n m=A(i,j)*x(j);

if j==i m=0; end p=p+m; end x(i)=(b(i)-p)/A(i,i); end if max(abs(x-z))<0.00001 break; end v(:,k)=x; z=x; fprintf('%d\t%f\t',k,x); fprintf('\n'); end

METODO DE LA POTENCIA
%CALCULA LOS VALORES Y VECTORES PROPIOS DE UNA MATRIZ POR EL METODO DE LA %POTENCIA A=input('ingrese la matriz A='); x=input('ingrese los vectores propios iniciales x='); M=input('Ingrese el numero de ieteraciones M='); fprintf('%d\t%f\t',0,x);a=0; b=0; fprintf('\n'); for k=1:M y=A*x; r=y(1)/y(2); x=y/norm(y); fprintf('%d\t%f\t%f\f',k,x,r); fprintf('\n'); if max(abs(x-a))<0.000001 || abs(r-b)<0.000001 break; end a=x;b=r; end

3.- IMPLEMENTE N MATLAB EL ALGORTM DE DIFERENCIAS DIVIDIDAS, APLIQU PARACALCULAR EL POLINOIO DE INTERPOLACION P(X) PARA en [-5,5] a) Usando 5 y despus 25 nodos igualmente espaciados grafique f(x) y p(x). comente. b) Hale el error delta aproximado p(x) de f(x) en algunos puntos x E [-5,5].

%DIFERENCIAS DIVIDIDAS clear a=input('ingrese la cota inferior a= '); b= input('ingrese la cota superior b= '); n=input('ingrese el numero de nodos n='); l=(b-a)/(n-1); syms x real; f=a;

F=@(x) ((x^5)*sin(x))/(exp(x)+tanh(x)); for k=1:n u(k)=f; y(k)=F(f); f=f+l; end for i=1:length(u) c(i,1)=y(i); end for j=2:length(u) for i=1:length(u)-j+1 c(i,j)=(c(i+1,j-1)-c(i,j-1))/(u(i+j-1)-u(i)); end end v=c(1,:); disp('los coeficientes son'); disp(v); pol=0; for p=1:n q=1; for z=1:p-1 q=q*(x-u(z)); end pol=pol +v(p)*q; end disp('el polinomio de interpolacion es pol'); disp(pol);

You might also like