Vectors scalar product

From: lijowski@cosray2.wustl.edu
Date: Wed Aug 26 1998 - 18:44:25 MEST


 Hello,

 Below is a test root macro calculating 4 cosines between two vectors
 using  arrays and also the root TVector. I got the same values 
 in both cases in last three iteration, but in the first iteration
 the cosine and the scalar product is zero. Any explanation?

 I have been running root 2.00/10 under SunOS 5.5.

 Thanks and regards,

  Michal Lijowski

------------------------------------------------------------------------
Michal Lijowski                  Washington University
Research Associate               St. Louis, MO 63130-4899, USA 
Department of Physics            phone:   314-935-6285
Campus Box 1105                  email:   lijowski@cosray2.wustl.edu
------------------------------------------------------------------------                            


{
  gROOT -> Reset();
  gBenchmark -> Start("test_vectors");


Double_t  av[4][2] = {
          -8.997,  -0.015,
          -9.021,  -0.260,
          -8.998,  -0.021,
          -9.021,  -0.027};
Double_t  bv[4][2] = {
           0.0260, -8.982,
           0.0250, -8.988,
           0.0340, -8.985,
           0.0280, -8.992};

  TVector  va(0, 1), vb(0, 1);
  for (Int_t  jj = 0; jj < 4; jj++) {
       Double_t  avn = sqrt(av[jj][0] * av[jj][0] + av[jj][1] * av[jj][1]);
       Double_t  bvn = sqrt(bv[jj][0] * bv[jj][0] + bv[jj][1] * bv[jj][1]);
 
       Double_t  cosine = (av[jj][0] * bv[jj][0] + av[jj][1] * bv[jj][1]) / (avn * bvn);

       printf(" %d  av   %f   %f   bv   %f   %f  cosine  %f\n", jj, av[jj][0], av[jj][1], bv[jj][0], bv[jj][1], cosine);

       Int_t  ll = 0;         
       for  (Int_t ii = va.GetLwb(); ii <= va.GetUpb(); ii++) {
           va(ii) = av[jj][ll];
           vb(ii) = bv[jj][ll];
           ll++;
       }
       va.Print();
       vb.Print();
       printf("  cosine  %f\n", Assert(va * vb) / (sqrt(va.Norm2Sqr() * vb.Norm2Sqr())) );
   }
   gBenchmark -> Show("test_vectors");
  }


This is output.

 0  av   -8.997000   -0.015000   bv   0.026000   -8.982000  cosine  -0.001227
  cosine  0.000000
 1  av   -9.021000   -0.260000   bv   0.025000   -8.988000  cosine  0.026029
  cosine  0.026029
 2  av   -8.998000   -0.021000   bv   0.034000   -8.985000  cosine  -0.001450
  cosine  -0.001450
 3  av   -9.021000   -0.027000   bv   0.028000   -8.992000  cosine  -0.000121
  cosine  -0.000121



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:37 MET