Message Boards Message Boards

0
|
3435 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Fitting Compiled function

Posted 10 years ago

I am trying to fit data with a compiled function, however I receive error message, I don't understand why:

dat = Join[Table[{RandomReal[], RandomReal[]}, {i, 10}], 
   Table[{RandomReal[{1, 2}], RandomReal[{1, 2}]}, {i, 10}]];
kk = Compile[{{a, _Real}, {b, _Real}, {x, _Real}}, a + b x]
NonlinearModelFit[data, kk[a, b, x], {a, b}, x]

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

Any ideas how to fix it? Thanks!

POSTED BY: Al Guy
2 Replies
Posted 10 years ago

I see, thanks.

POSTED BY: Al Guy

In the course of executing within NonlinearModelFit the function kk is being evaluated with symbolic arguments, hence the warning message. The way to avoid the warning message is not to use a compiled function in this case. However, you still get a result (and the correct one) because when a CompiledFunction encounters a case where the arguments supplied to it are not numerical it will default to evaluating with the original expression. So one way to fix this is to wrap your kk with Quiet ;-) as in

NonlinearModelFit[dat, Quiet[kk[a, b, x]], {a, b}, x]

Basically you tell it to shut up.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract