[Insight-users] vnl_diag_matrix

Kumar T.R. MaKumartr at netscape . net
Mon, 12 May 2003 12:41:05 +0000


--------------070403000704030203070004
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello Everyone

I observe that vnl_diag_matrix is intelligent (atleast  smart)

This I say because it crops itself to the size necessary for multiplication

So if there is a 3x3 diagonal matrix and a 6x6  diagonal matrix
Both can multiply with a 3x3 matrix (or can be even mutliplied)
and you get the same result

For this I have attached a sample program for evaluating the same

And the result is as below

See A now
13 21 43
47 25 66
14 57 61

See B now
2 0 0
0 3 0
0 0 4

See B*A now
26 42 86
141 75 198
56 228 244

See B now
2 0 0 0 0 0
0 3 0 0 0 0
0 0 4 0 0 0
0 0 0 5 0 0
0 0 0 0 6 0
0 0 0 0 0 7

See B*A now
26 42 86
141 75 198
56 228 244

Strange but true
I would be happy to receive any comments regarding the same

Regards
Kumar

--------------070403000704030203070004
Content-Type: text/plain;
 name="VNL_try.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="VNL_try.cxx"

#include <vnl/vnl_matrix.h>
#include <vnl/algo/vnl_real_eigensystem.h>
#include <vnl/vnl_matrix_fixed.h>

//vnl_real_eigensystem.h> 
#include <vcl_iostream.h>

#include <vcl_iterator.h>  // ostream_iterator
#include <vcl_algorithm.h> // copy
//#include <vcl_double.h>    // double




using namespace std;




int main(int argc, char* argv[])
{
  

  vnl_matrix_fixed<double,3,3> A; // 3x3 matrix, elements not initialized
  
  
  vnl_vector<double>  One(3);
  vnl_vector<double> Two(6);
  
  vnl_diag_matrix<double>  B;
  

  One.put(0,2);
  One.put(1,3);
  One.put(2,4);
 
  Two.put(0,2);
  Two.put(1,3);
  Two.put(2,4);
  Two.put(3,5);
  Two.put(4,6);
  Two.put(5,7);

A(0,0) = 13; // Set top-left component of A.
A(0,1) = 21;
A(0,2)=  43;

A(1,0)=47;
A(1,1)=25;
A(1,2)=66;  

A(2,0)=14;
A(2,1)=57;
A(2,2)=61; 


vcl_cout <<" See A now \n " <<  (A).get_n_rows(0,(A).rows()) << "\n"; 

 B.set(One.extract(One.size(),0));
 vcl_cout <<" See B now \n " <<  B.asMatrix().get_n_rows(0,B.rows()) << "\n"; 
 vcl_cout <<" See A*B now \n " <<  (A*B).get_n_rows(0,(B*A).rows()) << "\n"; 


 B.set(Two.extract(Two.size(),0));

 vcl_cout <<" See B now \n " <<  B.asMatrix().get_n_rows(0,B.rows()) << "\n"; 
 vcl_cout <<" See A*B now \n " <<  (A*B).get_n_rows(0,(B*A).rows()) << "\n"; 
}

--------------070403000704030203070004--