I want to do the following in Mathematica

```
Table[p[i], {i, -3, 0}] = Flatten[{Table[0, {i, -3, -1}], 1}]
```

But I got an error:

```
Set::write: Tag Table in Table[p[i], {i, -3, 0}] is Protected.
```

However, it is perfectly fine to do:

```
{p[-3], p[-2], p[-1], p[0]} = Flatten[{Table[0, {i, -3, -1}], 1}]
```

Many thanks!

Force the LHS to evaluate into pieces that can be assigned to:

Evaluate[Table[p[i], {i, -3, 0}]] = Flatten[{Table[0, {i, -3, -1}], 1}]

The reason it doesn't work is because `Set`

has attribute `HoldFirst`

. It means that `Set[a,stuff]`

passes symbol `a`

instead of value of `a`

to `Set`

function. As to why it has this attribute, ask yourself: when you do `Set[a,stuff]`

, do you want to assign `stuff`

to symbol `a`

, or to the value of `a`

?

In your example, `a`

holds a table of variable names, so you want the value of `a`

and `HoldFirst`

is annoying. However, most of the time `a`

will have a value like `5`

and you want `a=stuff`

to assign `stuff`

to symbol `a`

, not to the value `5`

A common pattern to get around Holding attributes is the following:

```
Set@@{Table[p[i], {i, -3, 0}],Flatten[{Table[0, {i, -3, -1}], 1}]}
```

Similar Questions

Does mathematica have something like select any that gets any element of a list that satisfies a criterion?

how to record/monitor java field assignment operation ; for example , i want to add some function before or after the assignment operation; original code : class Test{ public String name; public void

I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function Prime. I had search about MathLink but how to use it in Python is

Version 8.0.1 of Mathematica has just been released and it didn't fix the bug that has been most annoying me. This is a known bug and WRI promise to fix it in a future release. Until they do, maybe

Given a list of numbers in Mathematica, how would I extract from that list the total number of numbers between numbers a and b that I specify?

Mathematica is giving me a weird output when I am asking for a specific element of a nested list. I have: testroots = {{0, 0, 0}, {0, 0, 0}} When I ask for testroots[[0,0]] which should give me a 0,

Let's say I have a list: list=Table[{RandomReal[],RandomReal[],RandomReal[]}, {i,1,100}]; I'd like to make a new list based on conditions. Now I've seen that I should use the Select function, but I d

How can i fix the maximum size of std::list ? Let's say that the maximum is 100, so my std::list will have a size that vary from 0 to 100.

I have a list of dates and values in the format: {{{dateInfo1},value1},{{dateInfo2},value2},...,{{dateInfoN},valueN}} With some actual dates and values: {{{1971, 1, 31, 0, 0, 0.}, 1.0118}, {{1971, 2

Due to the fact that mysql is a declarative language, I can't find a way to force assignment variable order. Take this query : SET @v1=0; SET @v2=0; SELECT @v1, @v2 FROM MyTable table WHERE (@v1:=@v2

I don't know why Wikipedia lists Mathematica as a programming language with printf. I just couldn't find the equivalent in Mathematica. My specific task is to process a list of data files with padded

I've made this pinball game program as an assignment for my class, and I've been stuck trying to fix the pinball movement and collision. The first problem is that no matter which direction the user se

I'm very close to being done, but can't quite figure out how to tie everything together. I have the separate methods responsible for their particular task, but i feel like my cohesion is really bad. n

I am wondering how I can write a function to be used in the Apply function in Mathematica? For example, I want to trivially re-implement the Or function, I found the following Apply[(#1 || #2)&,{a

I need to create a 3 by 3 real orthonormal symbolic matrix in Mathematica. How can I do so?

I would like to take a python dictionary of lists, convert the lists to numpy arrays, and restore them in the dictionary using list comprehension. For example, if I had a dictionary myDict = {'A':[1,2

Can Mathematica do Bayes Rule conditional probability calculations, without doing the calculation manually? If so how? I have been searching both the Mathemtaica doco and the web for a hint but cannot

I would like to know how to round to 1 decimal place of the numbers in an expression. For instance, the mathematica gave me 0.7888888888000002*x+1.0000000002*x^2+2.1000002*x^3==0, I want to know how d

I have a file with 40,000 data points. In Matlab I can use the plot command to draw the plot: aaa = Import('file Name'); plot(aaa,mesh) How do I do it in Mathematica? I tried: aaa = Import[File Nam

How can I fix the problem of Incomplete Implementation? View of Controller.m : #import Quiz_GameViewController.h @implementation Quiz_GameViewController @synthesize theQuestion, timer, theScore, th

The following Mathematica code generates a highly oscillatory plot. I want to plot only the lower envelope of the plot but do not know how. Any suggestions wouuld be appreciated. tk0 = \[Theta]'[t]*\[

I am wondering if an initializer_list<T> requires that T has an assignment operator. The following struct Foo { Foo& operator=( const Foo& ) = delete; }; std::vector<Foo> f = { Foo

I want to teach mathematica that Subscript[w, i] differentiated by Subscript[w, j] is KroneckerDelta[i, j]. I tried Unprotect[D]; D[Subscript[x_, i_], Subscript[x_, j_]] := KroneckerDelta[i, j]; Prot

How to fix this analysis issue: CODE if(![super initWithFrame:CGRectZero]){ return nil; } firstOfPrev = -1; marks = markArray; monthDate = date; startOnSunday = sunday;

I am stuckwith a fairly simple problem: I need to construct a list with all permutations of values from two different lists in Mathematica. Let say, a={1,2} and b={4,5} I would need the result c={{1,4

How do I loop this? p = Table[RandomChoice[{Heads, Tails}, 2 i + 1], {i, 10}]; v = Count[#, Heads] & /@ p; c = Count[#, Tails] & /@ p; f = Abs[v - c]; g = Take[f, LengthWhile[f, # != 3 &]

Could you please give me a hint how can I invoke a java project (written in eclipse) from Mathematica? I want to give values generated by my Mathematica program as input to a java project, and use the

How do you set up manipulate so that you can control a variable with a vertical slider instead of a horizontal slider in Mathematica?

We suppose that for example i have a string, and i want to escape it, and to be well reading) need a working extension what will solve this problem i tried. var t = '; t.Escape();// == %27 (what i

I have this code: while (list ($key, $val) = each ($ethnicity)) { if ($val == '') $ethnicity = ''; break; } and I get an error saying: Assignment in condition, Change to == But I can't change it to =

On this page http://browserupdate.microdual.com/ i have a bug on Internet Explorer. How to fix it? I had already used the DD_belatedPNG.fix() function, but it didn't worked. Thanks to all

I'm struggling how to get rid of expressions that are trivially zero in Mathematica from the output. Example: pVec = Table[{i, Exp[-i*0.03]}, {i, 0, 2.5, 1/2}]; pVec[[2, 2]] = p1; pVec[[3, 2]] = p2;

I'm just getting started on Mathematica and trying to define a function for later use. The function is: test[x_]:=x^2 While I don't close Mathematica, I can use the function on my notebooks but when

I have data(points) that I have to import from another program to Mathematica, so I can plot it. I have control on how the points are going to be written to the file, so I can put them in any way I wa

I would like to know how to exchange data between Mathematica and a C/C++ with pipes. In the Mathematica tutorial it says that when you open a file or a pipe, Mathematica creates a 'stream object' th

I have to port a lot of files from Mathematica to Octave. I found a Lisp Mathematica parser from ~1991 but I am not really familiar with Lisp, so I was wondering if anyone has any experience with port

I have a variable called result which is a List<List<string>> I want to parse each element and fix it (remove white spaces, etc) i = 0; foreach (List<string> tr in res) { foreach (

I am trying to replicate Lagrange Interpolating Polynomials in Mathematica. The wiki for an explanattion of them can be seen here. This is my code (sorry I don't know how to place mathematica code in

I am a bit at a loss how to do the following efficiently in Mathematica: a = { 1, 2, 3, 4, 5 }; (* list of integers *) b = { 2, 4, 6, 8 }; (* another list of integers *) filter = Table[MemberQ[b, elem

Is it true that Mathematica's Minimize function does not allow constraints like Mod[x,2]==0? I am trying to solve a MinuteMath puzzle with Mathematica: What is the smallest possible average of four d

I'm trying to plot a couple of UnitStep functions, but for some reason, Mathematica won't plot the whole function - Just the top (it doesn't look like a step, more like a line). How do I tell mathemat

I am trying to use a list which is passed to a function in such a way that I can get the length of that list get the individual x and y values to manipulate The list I am trying to manipulate can be

I am just beginning with python and I've run in to an error I don't know how to fix. Please see the code examples below. I run event_timer.py and I get the following error message. Both of the files l

Suppose in Mathematica I define the following function: f[list_] := Map[Prime[Sow[#]] &, list]; which outputs a list of prime numbers, such that if the input list has n at position i, then the ou

I have the following setup which is giving me a message stating that Constructor Calls Overridable Method. I know this is happening, but my question is how to fix it so that the code still works and

I'm sure this is an incredibly simple question but I've recently started using Mathematica so it's all new to me. How do you scale the y axis? I try the following but it won't compile. Plot[y = {Exp[-

Thr version of Python is 2.6.6 n = 0 list1=[,,] list2=[] for ... : # a b c changes every loop list1[0]=a list1[1]=b list1[2]=c list2[n].append(list1) n += 1 for j in range(n): print list2[j] Th

How does Mathematica decide when to round numbers in its output? For example, giving the input 250000.5 gives the output 2500001 While 25000.5 is indeed printed as 25000.5 N[] isn't helpful here

I'm interested in calling fortran codes in a Mathematica session. I learn that Mathlink offers a way to do that. But I have little knowledge on C and nothing on C++. Is anybody willing to give me a de

When plotting a function using Plot, I would like to obtain the set of data points plotted by the Plot command. For instance, how can I obtain the list of points {t,f} Plot uses in the following simpl