0
$\begingroup$

So I have a big list of 75 polynomials which I need to apply a sequence of operations to.

My original program (an extract of which is below) worked fine:

x[z_] := (1 - 4*z^2 + z^4)*(1 + 4*z^2 + z^4)
k[z_] := -108*z^4*(1 + z^4)^4 
qsquared[z_] := Simplify[x[z]^3 - k[z]];
qdegree = Exponent[qsquared[z], z];
qcoeff = Coefficient[qsquared[z], z, qdegree]; ...

However, I have 75 x and k. What I wanted to do is start the program with them all just listed

Array[x, 76]
Array[k, 76]  

x[1][z_] := 4*(1 + 12*z + 4*z^3 + 11*z^4 - 6*z^5 + 7*z^6 - 2*z^7 + z^8)
k[1][z_] := -432*(31 + 14*z - 3*z^2 + 18*z^3 - 5*z^4 + 4*z^5)
x[2][z_] :=  (1 + z^2)*(1 + 27*z^2 + 27*z^4 + 9*z^6)
k[2][z_] := 64*z^2*(3 + 3*z^2 + z^4)
x[3][z_] := 4*(1 + 4*z - 16*z^2 + 12*z^3 + 27*z^4 - 18*z^5 - 9*z^6 +18*z^7 +9*z^8)
k[3][z_] := 16*(-1 + 4*z)^3*(21 - 6*z - 9*z^2 + 14*z^3 + 9*z^4)

And so on. I then tried looping through with:

Do[
 qsquared[z_] := Simplify[x[i][z]^3 - k[i][z]];
 qdegree = Exponent[qsquared[z], z];
 qcoeff = Coefficient[qsquared[z], z, qdegree];
.....
, {i, 76}]

Which gets a Set::write error.

$\endgroup$
0
$\begingroup$

Try Table to list your results

Table[qsquared = Simplify[x[i][z]^3 - k[i][z]];qdegree = Exponent[qsquared, z];
{qsquared, qdegreeCoefficient[qsquared, z, qdegree]}, {i, 3}]
(*{{432 (31 + 14 z - 3 z^2 + 18 z^3 - 5 z^4 + 4 z^5) +64 (1 + 12 z + 4 z^3 + 11 z^4 - 6 z^5 + 7 z^6 - 2 z^7 + z^8)^3,1536}
, {(-1 + 54 z^2 + 297 z^4 + 504 z^6 + 405 z^8 + 162 z^10 + 27 z^12)^2,17496}
, {16 (-5 + 21 z - 63 z^2 + 270 z^4 - 216 z^5 - 252 z^6 + 
 432 z^7 + 162 z^8 - 270 z^9 + 162 z^11 + 54 z^12)^2, 1119744}}*)
$\endgroup$
0
$\begingroup$

Replace Array[x, 76] and Array[k, 76] with Clear:

ClearAll[x, k];
x[1][z_] := 4*(1 + 12*z + 4*z^3 + 11*z^4 - 6*z^5 + 7*z^6 - 2*z^7 + z^8)
k[1][z_] := -432*(31 + 14*z - 3*z^2 + 18*z^3 - 5*z^4 + 4*z^5)
x[2][z_] :=  (1 + z^2)*(1 + 27*z^2 + 27*z^4 + 9*z^6)
k[2][z_] := 64*z^2*(3 + 3*z^2 + z^4)
x[3][z_] := 4*(1 + 4*z - 16*z^2 + 12*z^3 + 27*z^4 - 18*z^5 - 9*z^6 +18*z^7 +9*z^8)
k[3][z_] := 16*(-1 + 4*z)^3*(21 - 6*z - 9*z^2 + 14*z^3 + 9*z^4)

Your previous definitions of x[z_] and k[z_] as polynomials are cause problems with defining the subvalues x[1][z_] etc.: The head x[1] evaluates to the integer -12, so your code in effect tries to define (-12)[z_], which is not allowed.

It might be better to put the polynomials in two lists (or a 2 by 75 or 76 array), and manipulate the lists than to define separate functions. It's hard to say without the seeing the full application. But you didn't ask about it anyway.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.