Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: matrix operations -- shared data vs copied

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65944] Re: matrix operations -- shared data vs copied
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 24 Apr 2006 06:01:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 4/23/06 at 6:17 AM, robert.dodier at gmail.com wrote:

>I'm trying to get a handle on what Mathematica does with some matrix
>operations. I wasn't able to figure it out by web or newsgroups
>search so maybe you can help.

>Suppose A is a matrix. Consider these operations.

>(1) B = A

>(2) myfunction[A]

>(3) B = (some way of extracting column 1 of A)

>(4) B = (some way of pasting A onto another matrix)

>The question of interest is whether modifying elements of A also
>modify B after operations (1), (3), and (4), and whether
>modifications of the formal argument within myfunction also modify
>the actual argument (namely A).

One of the best ways and probably the most direct way to answer questions like this is to simply try it out and see what happens. For example, I can create a simple 3 x 3 matrix named A and set B to be the same as follows:

A = Partition[Range@9, 3];
B = A;

then doing

In[13]:=
A=A A;
A==B

Out[14]=
False

clearly showing modifications to A do not alter B. Further if I do,

In[15]:=
A==B B

Out[15]=
True

followed by

In[16]:=
B==A

Out[16]=
False

which shows a function applied to a matrix doesn't change the matrix unless you explicitly set the matrix to be the result as I did with A = A A above.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Re: Limit bug?
  • Next by Date: Re: How to extract functions from a list and call them with any argument?
  • Previous by thread: Re: matrix operations -- shared data vs copied
  • Next by thread: Re: matrix operations -- shared data vs copied