1

I try to compile this code, but always failed, could anybody guide me?

a = 1; n = 10; list = Table[1.1, {i, n}];
f = Compile[{{list, _Complex, 1}}, p = Table[0, {i, n}];
  Do[p[[i + 1]] = 2 p[[i]] - list[[i]] a^2, {i, 1, n - 1}];
  p - p[[n/2]]]
f[list]
dnvin
  • 47
  • 4

1 Answers1

3

You are against the 2nd and 4th rule mentioned in this post. After modifying according to the rules, f compiles successfully:

a = 1; n = 10; list = Table[1.1, {i, n}];
f = With[{a = a, n = n}, 
  Compile[{{list, _Complex, 1}}, Module[{p = Table[0 + 0 I, {i, n}]},
    Do[p[[i + 1]] = 2 p[[i]] - list[[i]] a^2, {i, 1, n - 1}];
    p - p[[n/2 // Round]]]]]
f[list]
xzczd
  • 65,995
  • 9
  • 163
  • 468