1
$\begingroup$

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]
$\endgroup$
3
$\begingroup$

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]
$\endgroup$
  • $\begingroup$ Thank you very much! $\endgroup$ – dnvin Oct 31 '18 at 7:16

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.