This example show how initialize a matrix with the matrix module. * inverse : inv(m) or .inv.m (gauss-jourdan) * pseudo-inverse : pinv(m) by default "cholesky decomposition, fast" or pinv(m,type_met More details about this example.
00001 00017 program matrix_analysis2 00018 00019 use mod_matrix ! use matrix module 00020 00021 #include "fml_constants.h" 00022 implicit none 00023 !********************************************* declaration 00024 00025 integer :: m2_rows = 4, m2_cols = 5 !size of m1 00026 integer :: m3_rows = 5, m3_cols = 5 !size of m1 00027 00028 ! declaration of matrix m2 00029 type(matrix) :: m2; 00030 ! declaration of matrix m3 00031 type(matrix) :: m3; 00032 ! declaration of matrix m_res 00033 type(matrix) :: m_res; 00034 00035 !********************************************* body 00036 !indication: p_notcast is defined in fml_constants.h (adapt the format) 00037 ! init of a matrix m3 00038 call init(m3,m3_rows,m3_cols); !init:=m_init 00039 ! init of a matrix m2 00040 call init(m2,m2_rows,m2_cols); !init:=m_init 00041 00042 !initialize m1 by random values between 1.0 and 10.0 00043 call random(m2,low=p_notcast(1.0),high=p_notcast(10.0)) !random:=vc_random 00044 !initialize m3 by random values between 2.0 and 6.0 00045 call mc_diagDominant(m3,m3_rows,low=p_notcast(1.0),high=p_notcast(1.5)) !dominant diagonal 00046 00047 print*; !newline 00048 00049 print*, "********************************************* matrix mathematics proprieties" 00050 print*, "m3="; 00051 call print(m3); !print m3 (print:=m_print) 00052 print*, ">>>>>>>>>>>>>>>>>>>> inverse of m3=" 00053 m_res=inv(m3) ! inverse by gauss-jourdan, we can use the operato .inv., like .inv.m3 00054 print*, "**** inv(m3)=" 00055 call print(m_res); 00056 print*, "**** inverse verification by m3*inv(m3)=I_3" 00057 call print(m3*m_res); 00058 print* 00059 00060 print*, ">>>>>>>>>>>>>>>>>>>> pseudo-inverse of m2=" 00061 m_res=pinv(m2,meth_pinv='svd') ! pseudo-inverse by svd 00062 print*, "**** svd::pinv(m2,meth_pinv='svd')=" 00063 call print(m_res); 00064 m_res=pinv(m2) ! or pinv(m2,meth_pinv='chol') pseudo-inverse by cholesky 00065 print*, "**** svd::pinv(m2,meth_pinv='svd')=" 00066 call print(m_res); 00067 print*; 00068 print*, "**** pseudo-inverse verification by Moore-Penrose conditions" 00069 print*, "## m2.m2^+m2 = m2" 00070 call print(m2*m_res*m2) 00071 print*, "m2="; 00072 call print(m2); 00073 print*;print*, "## m2^+m2 m2^+= m2^+" 00074 call print(m_res*m2*m_res) 00075 print*, "m2^+="; 00076 call print(m_res); 00077 print*;print*, "## (m2.m2^+)^* = m2.m2^+" 00078 call print(.tr.(m2*m_res)) 00079 print*, "m2.m2^+=" 00080 call print(m2*m_res) 00081 print*;print*, "## (m2^+.m2)^* = m2^+.m2" 00082 call print(.tr.(m_res*m2)) 00083 print*, "m2^+.m2=" 00084 call print(m_res*m2) 00085 00086 print* 00087 print*;print*, "... ... ... ... ... ... ... deallocate matrix" 00088 call destruct(m2) ! destruct the matrix m2 00089 call destruct(m3) ! destruct the matrix m3 00090 call destruct(m_res) ! destruct the matrix m_res 00091 print*; 00092 end program matrix_analysis2