Question

Hi,all

My question is about the Vector operator "-". Here is a pice of simple code:

Vector<double> v1(3,1.0);    // vector [ 1 1 1]
Vector<double> v2(3,0.0);

Matrix<double> m1(3,3,1.0);
Matrix<double> m2(3,3,0.0);

// please pay attention that the v1 will be changed after execute the following code
// and I think this is unexpected
v2 = -v1;                            // v1=[-1 -1 -1]

cout<<"v1="<<v1<<endl
      <<"v2="<<v2<<endl;

// please pay attention that the m1 will not be changed after execute the following code,
// and I think this is expected
m2 = -m1;

cout<<"m1="<<m1<<endl
      <<"m2="<<m2<<endl;

When I working with Vector like this,v2=-v1, the value of v1 was changed while v1 keeping const expected, I think this is not consistent with our habit. Is the vector opertor designed to work like that?

In fact, I'm writing a satellite orbit propagator base on the gpstk Matrix library, incorrect results were got before I take a whole night to locate the problem. Attention should be paid to the Vector operator "-" by the users of gpstk. If possible, wish some one can improve it. Thank you.

Regards

YAN Wei

-- YanWei - 19 May 2009

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

I can confirm this is the the behavior of the Vector class. I have a fix that I will hopefully submit in the near future for it. The reason I am waiting to submit is to confirm with others who have been working on the toolkit longer than myself that this is not the expected behavior for the Vector class and to make sure that this change won't cause other things to break.

-- AllenFarris - 01 Jul 2009

I's nice someone can check the problem. Thank you,Allen!

-- YanWei - 02 Jul 2009

Someone else in the lab just committed a change that I think fixes this problem (revision 2005). I've run the test that I wrote in addition to the code that you posted and both seem to be working as expected now. Go ahead and check to make sure it is working and if so set the status of this question to answered.

-- AllenFarris - 02 Jul 2009

It's working as expected now, Thank you.

-- YanWei - 04 Jul 2009 No such template def TMPL:DEF{PROMPT:supportquery}

Topic revision: r5 - 04 Jul 2009, YanWei
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback