MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

FindRoot + Compile = incompatible (?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111273] FindRoot + Compile = incompatible (?)
  • From: "Scot T. Martin" <smartin at seas.harvard.edu>
  • Date: Mon, 26 Jul 2010 06:35:48 -0400 (EDT)

Has anyone ever run into the problem of trying to use Compile'd functions 
within FindRoot?

The error message is:

"CompiledFunction::cfsa: Argument y at position 1 should be a machine-size 
real number."

[Yes, the function still evaluates but in doing so the purpose of compile 
& speed gets defeated.]

The explanation for this error messages is found in ref/FindRoot:

"FindRoot first localizes the values of all variables, then evaluates f 
with the variables being symbolic [1], and then repeatedly evaluates the 
result numerically." [1] That's why Compile[] fails.

Here is a specific example of code that shows the problem:

*****

func = Compile[{x}, x^2];

FindRoot[func[y] == 1, {y, 0.5, 1.5}]

*****

Anyone have thoughts on how to work around this aspect so that Compile'd 
functions can work within FindRoot and thus accelerate evaluation thereof? 
[Or is there an inherent reason why they shouldn't?]

[My actual function is not "func"; my actual func is 3x faster as a 
Compile'd, hence my motivation to get FindRoot to work.]

Thanks!



  • Prev by Date: Re: All pairs shortest paths
  • Next by Date: Re: Documentation on (Color) Blend
  • Previous by thread: Re: NDSolve - how to bypass safety chceck?
  • Next by thread: Re: FindRoot + Compile = incompatible (?)