function A=MatSym(n)
  A=rand(n,n);
  for (i=1:1:n)
    for (j=i+1:1:n)
      A(i,j)=A(j,i);
    end
    end 
  endfunction
  
function A=MatSDP(n)
  A=MatSym(n);
  [D,P]=bdiag(A);
  D=abs(D);
  D=D+norm(D)*eye(D);
   A=P*D*inv(P);
endfunction
 
function [B]=Cholesky(A)
n=size(A,"r");  
for (j=1:1:n)
  for (k=1:1:j-1)
    A(j,j)=A(j,j)-A(j,k)^2;
  end
A(j,j)=sqrt(A(j,j));
  for (i=j+1:1:n)
    for (k=1:1:j-1)
     A(i,j)=A(i,j)-A(i,k)*A(j,k);
   end
   A(i,j)=A(i,j)/A(j,j);
   end
 end
 B=A;
endfunction

function y=DescenteCh(Ch,b)
n=size(Ch,"r");  
//Resolution de Ly=b
y(1)=b(1)/Ch(1,1);
for i=2:1:n
  S=0;
  for j=1:1:i-1
    S=S+Ch(i,j)*y(j);
    end  
y(i)=(b(i)-S)/Ch(i,i);
end
endfunction

function [x]=ResoutCh(A,b) 
n=size(A,"r"); 
Ch=Cholesky(A);
y=DescenteCh(Ch,b);
x=RemonteeU(Ch',y);
endfunction


function tempsCh()
  i=10;
  while (i<110)
    A=MatSDP(i);
    tic();
    Cholesky(A);
    a=toc();
    tic();
    FacLU(A);
    b=toc();
    x(i/10)=a;
    y(i/10)=b;
    i=i+10;
  end
  z=1:1:10;
  clf()
  plot(z,x,'r')
  plot(z,y,'g')
  //scf(2)
 //plot(x,y);
endfunction

function [x,y]=temps2Ch()
  i=10;
  while (i<110)
    A=MatSDP(i);
    B=ones(i,1);
    tic();
    ResoutCh(A,B);
    a=toc();
    tic();
    ResoutLU(A,B);
    b=toc();
    x(i/10)=a;
    y(i/10)=b;
    z=1:1:10;
  end
plot(z,x,'r');
plot(z,y,'g');
endfunction
//function B=Chol(A)
//n=size(A,"r");  
//for (j=1:1:n)
//  for (k=1:1:j-1)
//    A(j,j)=A(j,j)-A(j,k)^2;
//  end
//A(j,j)=sqrt(A(j,j));
//  for (i=j+1:1:n)
//    for (k=1:1:j-1)
//     A(i,j)=A(i,j)-A(i,k)*A(j,k);
//   end
//   A(i,j)=A(i,j)/A(j,j);
//   end
// end
// B=A;
//endfunction

       



   
