UNIVERSIDAD PERUANA UNIÓN FACULTAD DE INGENIERÍA Y ARQUITECTURA E.P. Ingeniería Civil
Una Institución Adventista
RESOLUCION DE EJERCICIOS
CURSO: METODOS NUMERICOS Y PROGRAMACION
Autores: Miguel Angel Condori Chambi Docente: Lic. Elizabeth Milagros Gordillo
Juliaca - 2017
Ejercicios de programación de métodos numéricos Evaluación de practica 1.- EJEMPLO DE CHOLESKY >>S=[2 -1 0;-1 2 -1;0 -1 2] S= 2 -1 0 -1 2 -1 0 -1 2 >>chol(S) ans = 1.4142 -0.7071 0 0 1.2247 -0.8165 0 0 1.1547 N´otese que se obtiene un mensaje de error si la matriz no es definida positiva: >>T=[2 -1 0;-1 2 0;-1 -1 -1] T= 2 -1 0 -1 2 0 -1 -1 -1 >>chol(T) ??? Error using ==> chol Matrix must be positive definite. Programacion en Matlab:
2.- Programación generalizada Cholesky fprintf(' FACTORIZACION LU CHOLESKY\n\n\n'); A=input('Ingrese la matriz A = \n'); b=input('\nIngrese el vector b, correspondite a los terminos independientes b=\n'); [n,m]=size(A); C=[A,b]; disp(C) if n==m for k=1:n suma1=0; for p=1:k-1 suma1=suma1+L(k,p)*u(p,k); end
L(k,k)=sqrt(A(k,k)-suma1); u(k,k)=L(k,k); for i=k+1:n suma2=0; for q=1:k-1 suma2=suma2+L(i,q)*u(q,k); end L(i,k)=(A(i,k)-suma2)/L(k,k); end for j=k+1:n suma3=0; for r=1:k-1 suma3=suma3+L(k,r)*u(r,j); end u(k,j)=(A(k,j)-suma3)/L(k,k); end end producto=det(L)*det(u) if producto~=0 for i=1:n suma=0; for p=1:i-1 suma=suma+L(i,p)*z(p); end z(i)=(b(i)-suma)/L(i,i); %obtencion del vector Z end for i=n:-1:1 suma=0; for p=i+1:n suma = suma+u(i,p)*x(p); end x(i)=(z(i)-suma)/u(i,i); % solcion, calculos de las variables end else fprintf('\nEl determinante es igual a cero, por lo tanto el sistema tiene infinita o ninguna solucion\n') end end fprintf('\n Matriz Ab:\n') disp(C) fprintf('\n Matriz L:\n') disp(L) fprintf('\n Matriz U:\n') disp(u) fprintf('\n El vector Z:\n') disp(z) fprintf('\n\n La solucion de X1 hasta Xn es:\n'); for i=1:n xi=x(1,i); fprintf('\nX%g=',i) disp(xi); end 3.- algoritmo de método de gausiana
function [x] = Resuel_TriSup(A,b) n=length(b); x=zeros(n,1): x(n)=b(n)/A(n,n); for k=(n-1):-1:1 s=0; for j=(k+1):n s=s+A(k,j)*x(j); end x(k)=(b(k)-s)/A(k,k); end 4.- generalización de L Existe una única matriz triangular inferior L = [mi,j ] , con mi,i = 1, para i = 1, ..., n