This example show how use qr decomposition with the matrix module. More details about this example.
00001 00014 program matrix_qr 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_qr) :: decomp_qr; !type qr decomposition 00024 00025 !********************************************* body 00026 !initialize A by random vaqres 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*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> qr factorisation (HouseHolder)" 00036 decomp_qr=qr(A) ! m_decompqr !HouseHolder QR by default (meth_qr='gs') 00037 print*, "*** out :: Q matrix of qr ----> " 00038 call print(decomp_qr%Q) 00039 print*, "*** out :: R matrix of qr ----> " 00040 call print(decomp_qr%R) 00041 print*, "***### out :: verif matrix of qr : A=L*tr(L) ----> " 00042 print*, "A=" 00043 call print(A) 00044 print*, "Q*R=" 00045 call print(decomp_qr%Q*decomp_qr%R) 00046 print*; !newline 00047 00048 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> qr factorisation (Gram-Schmidt)" 00049 decomp_qr=qr(A,meth_qr='gsro') ! m_decompqr gram-schmidt reorthogonalization 00050 !use meth_qr='gs' for the classical gram-schmidt 00051 print*, "*** out :: Q matrix of qr ----> " 00052 call print(decomp_qr%Q) 00053 print*, "*** out :: R matrix of qr ----> " 00054 call print(decomp_qr%R) 00055 print*, "***### out :: verif matrix of qr : A=L*tr(L) ----> " 00056 print*, "A=" 00057 call print(A) 00058 print*, "Q*R=" 00059 call print(decomp_qr%Q*decomp_qr%R) 00060 print*; !newline 00061 00062 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> qr factorisation (HouseHolder) with permutation matrix" 00063 decomp_qr=qr(A,is_permuted=.true.) ! m_decompqr ,is_permuted=.true. 00064 print*, "*** out :: Q matrix of qr ----> " 00065 call print(decomp_qr%Q) 00066 print*, "*** out :: R matrix of qr ----> " 00067 call print(decomp_qr%R) 00068 print*, "*** out :: P, permutation matrix of qr ----> " 00069 call print(decomp_qr%P) 00070 print*, "*** out :: number of swops:", decomp_qr%swops 00071 print*, "***### out :: verif matrix of qr : P*A = qr ----> " 00072 print*, "P*A=" 00073 call print(decomp_qr%P*A) 00074 print*, "Q*R=" 00075 call print(decomp_qr%Q*decomp_qr%R) 00076 print*; !newline 00077 00078 00079 call destruct(A) ! destruct the matrix A (don't forget to destruct the matrix) 00080 call destruct(decomp_qr) 00081 end program matrix_qr