Re: need help with vector multiplication

Rene van Paassen <[email protected]> Wed, 19 May 2004 16:01:05 +0200
Newsgroups gmane.comp.lib.mtl.devel
Organization Delft University of Technology, Aerospace Engineering
Message-ID <[email protected]>
On Wed, 2004-05-19 at 13:11, Uli Stein wrote:
> Hi all!
> 
> Something is going wrong in the following simple peace of code. I tried to
> keep it as simple as possible. Could someone please tell me what I'm doing
> wrong:
> 
> <SCHNIP>
> /********* TYPEDEFS *************************/
> typedef matrix<double,
>                rectangle<>,
>                dense<external>,                 
>                column_major >::type     extMatrix; //typedef for state space
> 
>                                                    //matrices and vectors,
> using 
>                                                    //"external data
> constructors"
> typedef matrix<double, 
>                rectangle<>, 
>                dense<>, 
>                column_major >::type     intMatrix; //"internal data
> constructors"
> 
> 
> /********* EXTERNAL DATA DECLARATION ********/
> double m_in1[3]; 
> double m_in2[3]; 
> double *m_c_array; 
> 
> // for example
> m_in1[0] = 1;
> m_in1[1] = 1;
> m_in1[2] = 1;
> m_in2[0] = 0;
> m_in2[1] = 0;
> m_in2[2] = 0;
> m_c_array[0] = 0;
> m_c_array[1] = 0;
> m_c_array[2] = 1;
> 
> /********* CODESAMPLE ***********************/
> double    temp_array[]={0,0,0};
> extMatrix  temp_vec(temp_array,M3,M1);    
> extMatrix  m_c_vec(m_c_array,M1,M3);
> intMatrix  result_vec(M1,M1);
> 
> // 1st COPY //
> CopyVector(temp_array, m_in1, 3);
> mult(m_c_vec, temp_vec, result_vec);  //<-- 'result_vec' has correct result
> m_result1 = result_vec(0,0);
> std::cout << "m_result1= " << m_result1 << ", size: ";
> print_all_matrix(result_vec);
> 
> // 2nd COPY //
> CopyVector(temp_array, m_in2, 3);
> mult(m_c_vec, temp_vec, result_vec); //<-- now, 'result_vec' hast the 	     
>                        //    same result as in the the 
>                                      //    "1st COPY" ?!

Yes, it is not mentioned in the documentation, but the matrix "mult"
multiplies and then *adds* to whatever there was in the result matrix. I
have no clue why this behaviour was defined like this, some
enlightenment, as well as a clear warning in the documentation, would be
welcome.


> m_result2 =  result_vec(0,0);
> std::cout << "m_result2= " << m_result2 << ", size: ";
> print_all_matrix(result_vec);
> 
> <SCHNAP>
> 
> 
> I thought, that I used the MTL function 'CopyVector()' and 'mult()'

Where did you get CopyVector?? it is not in my mtl headers. 

> correctly (I'm working on MSVC++ 6.0). It seems, that the 'IntMatrix
> result_vec' is not updated correctly by 'mult()'?! 
> I would be very grateful, if someone could show me where I made some
> mistakes. Probably they are of basic nature.
> 
> Thanks a lot! Regards,
> Uli

No thanks, 

René

_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/