Strange behavior when copying a vector

November 06 2011 by erik10 196
false
Maple

2


Dear Maple Users

I have encountered some strange behavior when trying to copy a vector:

In the first section I define a vector a and try to copy that vector and assign it to an variable b. Then changing the first coordinate in the copied vector b actually change the original vector as well. I found that behavior rather counter-intuitive. Is it working something like a Pointer in certain programming languages? I mean no extra memory is allocated for the "copy"?

In my second section I am trying to do the job in another way, using the package ArrayTools. Doing it this way seems to work the way I want: Only the copy b is changed. However something really disturbing happens, when I try to assign a value to the variable y. In writing the actual values of the vectors a and b, the value of y isn't substituted in b only a.  

 I am rather confused. I hope someone can bring some light into the issue!

Regards,

Erik

 
Loading Comments & Answers

You must be logged into your MaplePrimes account in order to post a comment. If you don't have an account, you can create an account here.

     

Forgot Your Password? Create an Account