test_kron Subroutine

subroutine test_kron()

Arguments

None

Contents

Source Code


Source Code

subroutine test_kron ()
   call lala( 'display(ones(80,1)''*61)')
   call lala( 'help kron')
   call lala( 'tally=[0];')
   call lala( [ character(len=256) :: &
     & '                                                                         ', &
     & 'lines(888888)                                                            ', &
     & '//  C = Kronecker product of A and B                                     ', &
     & 'A=rand(4);                                                               ', &
     & 'B=rand(4);                                                               ', &
     & '// ==========================================                            ', &
     & '// first, the hard way                                                   ', &
     & '[m, n] = shape(A);                                                        ', &
     & 'for i = 1:m, ...                                                         ', &
     & '   ci = A(i,1)*B; ...                                                    ', &
     & '   for j = 2:n, ci = [ci A(i,j)*B]; end ...                              ', &
     & '   if i = 1, C = ci; else, C = [C; ci];                                  ', &
     & '// ==========================================                            ', &
     & '// then the easy ways                                                    ', &
     & 'D=kron(A,B);                                                             ', &
     & 'E=A .*. B;                                                               ', &
     & '// ==========================================                            ', &
     & '// subtract the values from the expected results                         ', &
     & '// and sum the deltas. Could just compare C to E                         ', &
     & '// and C to D, of course.                                                ', &
     & 'S1=sum(abs(C-E))                                                         ', &
     & 'S2=sum(abs(C-D))                                                         ', &
     & '                                                                         ', &    
     & 'if S1=0, tally=[tally,0];display(''kron(A,B) check PASSED'');else,tally=[tally,1];display(''kron(A,B) check FAILED'');  ', &
     & 'if S2=0, tally=[tally,0];display(''A .*. B check PASSED'');else,tally=[tally,1];display(''A .*. B check FAILED'');      ', &
     & 'if sum(tally)=0,display(''kron PASSED'');else,display(''kron FAILED'');tally ', &
     & ''])
end subroutine test_kron