Advertisement
alva1515

doolittle

Nov 1st, 2018
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.91 KB | None | 0 0
  1. function [L,U] = doolittle (A)
  2.     //Reservar espacio para las matrices L y U
  3.     // Empezando con ceros hay sitios que ya no tendremos que tocar
  4.     L = zeros(size(A));
  5.     U = zeros(size(A));
  6.     [nRows, nColumns] = size(A);
  7.     //Recorremos en orden de columnas
  8.     for j=1:nColumns
  9.       for i=1:nRows
  10.         // Estamos por encima de la diagonal, hallamos elemento de U
  11.         if i<=j
  12.           U(i,j) = A(i,j);
  13.           for k=1:i-1
  14.             U(i,j) = U(i,j) - L(i,k)*U(k,j);
  15.           end
  16.         end    
  17.         // Estamos por debajo de la diagonal, hallamos elemento de L
  18.         if U(j,j)==0 then
  19.             mprintf("Matriz no valida, retornando");
  20.             return
  21.         end
  22.         if j<=i
  23.           L(i,j) = A(i,j);
  24.           for k=1:j-1
  25.             L(i,j) = L(i,j) - L(i,k)*U(k,j);
  26.           end
  27.           L(i,j) = L(i,j)/U(j,j);
  28.         end
  29.       end
  30.       end
  31.    endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement