# Tag Times in polynomial is Protected [duplicate]

I want to create a list of polynomials that start with 1 and have additional terms that are negative ie 1-x,1-x-x^2,1-x^9, etc to create a cool fractal by numerically solving them and plotting the roots in the complex plane. I'm doing this by creating lists of random integers between 0 and -1 and then adding a 1 to the beginning of the list. I then create polynomials from this list of coefficients. I want to be able to run this code multiple times so I can add more and more random polynomials to my list but I keep getting a "Tag Times in (1-z-z^2){} is Protected" error.

y = {}
while[i <= 20, coeffArr = RandomInteger[-1, 10]
coeffArr = Insert[coeffArr, 1, 1]
temp = z^Range[0, 10].coeffArr
y = Append[y, temp]
i = i + 1 ]
Set::write: "Tag Times in 2\ {1-z-z^2-z^4-z^6-z^9-z^10} is Protected"

• You need to separate commands with a semicolon. While needs to be capitalized. The third argument of While needs to be separated by a comma. Look up the commands in Help and work on the syntax. – bill s May 10 '17 at 3:32
• You're missing a semicolon between statements in the While loop. Should be while[i <= 20, coeffArr = RandomInteger[-1, 10] ; coeffArr = Insert[coeffArr, 1, 1];...] and so on. see here. – yohbs May 10 '17 at 3:33
• Also, While and For and their friends are not good Mathematica habits. I recommend considering more functional programming style, such as Map, Table and the like. See here for more. – yohbs May 10 '17 at 3:34

RandomSeed[0];

coeffArr := {1, RandomInteger[-1, 9]} // Flatten

poly := coeffArr.z^Range[0, 9]

ListPlot[
Table[ReIm[z] /. NSolve[poly, z], 5000] //
Flatten[#, 1] &,
Frame -> True,
Axes -> False,
AspectRatio -> Automatic]


Just another way:

p = 1 + z^Range[10].# & /@ RandomInteger[-1, {5000, 10}];
ListPlot[Join @@ (ReIm[z] /. NSolve[#, z] & /@ p),AspectRatio -> Automatic]