Re: Partial evaluation
- To: mathgroup at smc.vnet.net
- Subject: [mg21279] Re: Partial evaluation
- From: Tobias Oed <tobias at physics.odu.edu>
- Date: Tue, 21 Dec 1999 03:46:59 -0500 (EST)
- Organization: Old Dominion University
- References: <8320dg$glm@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Kevin Jaffe wrote:
>
> I'm sure this is a FAQ, but I haven't found the answer.
>
> First we define:
>
> In[1]:= A = {{0, 0}, {0, 0}}
>
> Out[1]= {{0, 0}, {0, 0}}
>
>
> Then the following assignment works:
>
> In[2]:= Part[A, 1, 1] = 1
>
> Out[2]= 1
>
> In[3]:= A
>
> Out[3]= {{1, 0}, {0, 0}}
>
> But this one doesn't:
>
> In[4]:= Part@@{A, 1, 1} = 2
>
> Set::write: Tag Apply in Part @@ {{{1, 0}, {0, 0}}, 1, 1} is Protected.
>
> Out[4]= 2
>
> In[5]:= A
>
> Out[5]= {{1, 0}, {0, 0}}
>
> And this is even worse, of course:
>
> In[6]:= Evaluate[Part@@{A, 1, 1}] = 2
>
> Set::setraw: Cannot assign to raw object 1.
>
> Out[6]= 2
>
> In[7]:= A
>
> Out[7]= {{1, 0}, {0, 0}}
>
> I understand the reasons for the error messages, but I don't know how
> to get around the problem. What I need is to partially evaluate the
> left-hand side of In[4], but I don't know how to do this.
>
> The reason I want to do things like "Part@@{A, 1, 1} = 2" is that I'm
> trying to write a module that must modify entries in an n_1 x n_2 x
> ... x n_k array A of arbitrary dimension k. I can compute the desired
> multi-index v = {i_1, i_2,..., i_k} for the array without knowing the
> array's dimension, but I can't figure a way to assign to the
> location A[[i_1, i_2, ..., i_k]].
>
> Is there any way to do what I'm trying to do?
>
> Thanks!
>
> KJ
>
> LYCOShop is now open. On your mark, get set, SHOP!!!
> http://shop.lycos.com/
> .
The simplest way is to create a new matrix and assign it to A
A = {{0, 0}, {0, 0}}
A=ReplacePart[A,1,{1, 1}]
Tobias