SHARE
TWEET

choleskyANDA

alva1515 Nov 1st, 2018 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [U, ind] = Cholesky(A)
  2.     eps = 1.0e-8
  3.     n = size(A,1)
  4.     U = zeros(n,n)
  5.    
  6.         for i = 1:n
  7.             t = A(i,i) - U(1:i-1,i)'*U(1:i-1,i)
  8.            
  9.             if t <= eps
  10.                 mprintf("Matriz no definida positiva.\n")
  11.                 ind = 0
  12.                return
  13.             end
  14.             U(i,i)= sqrt(t)
  15.            
  16.             for j = i+1:n
  17.                 U(i,j) = ( A(i,j) - U(1:i-1,i)'*U(1:i-1,j) )/U(i,i)
  18.             end
  19.         end
  20.     ind = 1
  21. endfunction
  22.  
  23. A = [16,-12,8,-16;-12,18,-6,9;8,-6,5,-10;-16,9,-10,46]
  24. X = [4,12,-16;12,37,-43;-16,-43,98]
  25. B = Cholesky(A); a = B' * B
  26. C = Cholesky(X); b = C' * C
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top