This example show how use cholesky decomposition with the matrix module. More details about this example.
00001 00014 program matrix_cholesky 00015 #include "fml_constants.h" 00016 use mod_matrix ! use matrix module 00017 implicit none 00018 00019 !********************************************* declaration 00020 integer, parameter :: m_size = 4 !size of m(A_size x m_size) 00021 ! declaration of matrix A 00022 type(matrix) :: A; 00023 ! declaration of matrix B 00024 type(matrix) :: B; 00025 !type contains cholesky matrix and the permutation if it's exist 00026 type(t_m_and_p) :: decomp_cholesky; 00027 00028 !********************************************* body 00029 !initialize A by random values between 1.0 and 10.0 00030 ! (dominant diagonal, positive definite) 00031 call mc_diagDominantSymmetric(A,m_size,low=p_notcast(1.0),high=p_notcast(6.5)) !dominant diagonal 00032 !init B matrix 00033 call init(B,m_size,m_size) 00034 !initialize B by random values between 1.0 and 10.0 00035 call random(B,low=p_notcast(1.0),high=p_notcast(6.5)) ! 00036 00037 print*; !newline 00038 print*, "********************************************* display initial data" 00039 print*,"* A="; 00040 call print(A); !print A (print:=m_print) 00041 print*; 00042 00043 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cholesky factorisation" 00044 00045 decomp_cholesky=chol(A) ! m_decompcholesky 00046 print*, "*** out :: L matrix of cholesky ----> " 00047 call print(decomp_cholesky%M) 00048 print*, "***### out :: verif matrix of cholesky : A=cholesky ----> " 00049 print*, "A=" 00050 call print(A) 00051 print*, "L*tr(L)=" 00052 call print(decomp_cholesky%M*.tr.decomp_cholesky%M) 00053 00054 print*; !newline 00055 print*, ">>>>>>>>>>>>>> Try to factorize B by cholesky" 00056 print*,"* B="; 00057 call print(B); 00058 print*; !newline 00059 decomp_cholesky=chol(B) ! m_decompcholesky 00060 !must throw an exception (because B is not positive definite) 00061 00062 call destruct(A) ! destruct the matrix A (don't forget to destruct the matrix) 00063 call destruct(B) 00064 call destruct(decomp_cholesky) 00065 end program matrix_cholesky