This example show how use svd decomposition with the matrix module. More details about this example.
00001 00014 program matrix_svd 00015 #include "fml_constants.h" 00016 use mod_matrix ! use matrix module 00017 implicit none 00018 00019 !********************************************* declaration 00020 integer, parameter :: m_size_r = 4, m_size_c = 5 !size of m(A_size_r x m_size_c) 00021 ! declaration of matrix A 00022 type(matrix) :: A; 00023 type(t_svd) :: decomp_svd; !type svd decomposition 00024 type(vector) :: sing_values !singular values 00025 00026 !********************************************* body 00027 !init A matrix 00028 call init(A,m_size_r,m_size_c) 00029 !initialize A by random values between 1.0 and 10.0 00030 call random(A,low=p_notcast(1.0),high=p_notcast(6.5)) 00031 00032 print*; !newline 00033 print*, "********************************************* display initial data" 00034 print*,"* A="; 00035 call print(A); !print A (print:=m_print) 00036 print*; 00037 00038 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> svd factorisation" 00039 00040 decomp_svd=svd(A) ! m_decompsvd (show other argument options) 00041 print*, "*** out :: U matrix of svd ----> " 00042 call print(decomp_svd%U) 00043 print*, "*** out :: S matrix of svd ----> " 00044 call print(decomp_svd%S) 00045 print*, "*** out :: V matrix of svd ----> " 00046 call print(decomp_svd%V) 00047 print*, "***### out :: verif matrix of svd : A=U.S.tr(V) ----> " 00048 print*, "A=" 00049 call print(A) 00050 print*, "U.S.tr(V)=" 00051 call print(decomp_svd%U*decomp_svd%S*.tr.decomp_svd%V) 00052 print* 00053 00054 print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> return only the singular values" 00055 sing_values=m_decompsvd_s(A) ! show other argument options 00056 write(*,'(A3)',advance='no') "S=" 00057 call print(sing_values) 00058 print*; !newline 00059 00060 call destruct(A) ! destruct the matrix A (don't forget to destruct the matrix) 00061 call destruct(sing_values) 00062 call destruct(decomp_svd) 00063 end program matrix_svd