Services & Resources / Wolfram Forums
MathGroup Archive
*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: setps problem/how to set matrix elements

  • To: mathgroup at
  • Subject: [mg65923] Re: setps problem/how to set matrix elements
  • From: "Nasser Abbasi" <nma at>
  • Date: Sun, 23 Apr 2006 06:17:43 -0400 (EDT)
  • References: <> <e22hg8$e6o$>
  • Reply-to: "Nasser Abbasi" <nma at>
  • Sender: owner-wri-mathgroup at

"Szabolcs Horvát" <szhorvat at> wrote in message 
news:e22hg8$e6o$1 at

 > and you get
> {{0.5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5}}[[1,1]]
> = 5;
> which is illegal.

in other words:

  A = {{1,2},{3,4}}

  A[[1,1]]   <----OK
 {{1,2},{3,4}} [[1,1]]  <---- OK

but when we try to assign to it, the second form fails

 A[[1,1]] = 5  <--- OK
 {{1,2},{3,4}} [[1,1]] = 5  <---- not OK

on a side question, does Mathematica always pass arguments to functions by 
value? (i.e. default is to evaluate all arguments being passed before the 
function being called gets hold of them?)

If a matrix A was one million by one million, then

F[a__]:= ... use matrix 'a'  here...

and then  I do  F[myBigMatrixA] then the whole thing is passed by value? and 
put of the stack?

So to force passing by reference, we prevent the evaluation of that specific 

Is there a document that describes more how Mathematica does these things. 
Calling convention, passing mechanism, and things sort of thing?


This is explained in the documentation of the error
> message (in version 5.2, not all messages are documented in all
> versions).
> You must prevent the first argument of FSD from being evaluated, so r
> will be replaced by p instead of the value of p. See the documentation
> of attribute HoldFirst.
> In[4]:=
> SetAttributes[FSD, HoldFirst]
> In[5]:=
> FSD[p,256,256]
> In[6]:=
> p
> Out[6]=
> {{5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5},{0.5,0.5,0.5,0.5}}
> After applying the attribute, the function works correctly, and
> p[[1,1]] is set to 5.
> Szabolcs Horvát

  • Prev by Date: Re: Where do I put my own add-on packages?
  • Next by Date: Troubles in NonlinearFit-Why always failed?
  • Previous by thread: Re: setps problem/how to set matrix elements
  • Next by thread: Re: Programming Problem with "if"