This example show how use lu decomposition with the matrix module. More details about this example.
00001 00014 program matrix_lu 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 type(t_lu) :: decomp_lu; !type lu decomposition 00024 00025 !********************************************* body 00026 !initialize A by random values between 1.0 and 10.0 00027 call mc_diagDominant(A,m_size,low=p_notcast(1.0),high=p_notcast(6.5)) !dominant diagonal 00028 00029 print*; !newline 00030 print*, "********************************************* display initial data" 00031 print*,"* A="; 00032 call print(A); !print A (print:=m_print) 00033 print*; 00034 00035 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LU factorisation" 00036 00037 decomp_lu=lu(A) ! m_decompLU 00038 print*, "*** out :: L matrix of lu ----> " 00039 call print(decomp_lu%L) 00040 print*, "*** out :: U matrix of lu ----> " 00041 call print(decomp_lu%U) 00042 print*, "***### out :: verif matrix of lu : A=LU ----> " 00043 print*, "A=" 00044 call print(A) 00045 print*, "L*U=" 00046 call print(decomp_lu%L*decomp_lu%U) 00047 print* 00048 print*, "out :: determinant of matrix by lu ----> ", det(A,meth_det='lu') 00049 print*; !newline 00050 00051 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LU factorisation with permutation matrix" 00052 decomp_lu=lu(A,is_permuted=.true.) ! m_decompLU ,is_permuted=.true. 00053 print*, "*** out :: L matrix of lu ----> " 00054 call print(decomp_lu%L) 00055 print*, "*** out :: U matrix of lu ----> " 00056 call print(decomp_lu%U) 00057 print*, "*** out :: P, permutation matrix of lu ----> " 00058 call print(decomp_lu%P) 00059 print*, "*** out :: number of swops:", decomp_lu%swops 00060 print*, "***### out :: verif matrix of lu : P*A = LU ----> " 00061 print*, "P*A=" 00062 call print(decomp_lu%P*A) 00063 print*, "L*U=" 00064 call print(decomp_lu%L*decomp_lu%U) 00065 print* 00066 print*, "out :: determinant of matrix by lu ----> ", det(A,meth_det='lu',is_permuted=.true.) 00067 00068 print*; !newline 00069 00070 call destruct(A) ! destruct the matrix A (don't forget to destruct the matrix) 00071 call destruct(decomp_lu) 00072 end program matrix_lu