Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.8K Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Use FindFit to get the rate constants for a chemical reaction?

Posted 7 years ago

Hi,

As the title says, I'm trying to find reaction rate constants using FindFit. Unfortunately, I'm getting the error "FindFit::nrlnum: The function value ... is not a list of real numbers with \ dimensions {512} at {Amp,k1,k1r,k3,k3r,k19,k20} = \ {424.5993497,82.,3.10^6,8.810^7,1.5*10^9,114000.,250.}"

The code is in the attached file. Please suggest ways to fix this - I don't understand what I'm doing incorrectly.

POSTED BY: Troy Wahl
3 Replies

You're welcome. I just checked, and you're right: the way the function is evaluated by FindFit, it's better to use memoization. I expected it to first evaluate the parameters and then insert the values for t (in which case you'd need to do the NDSolve only once), but it seems like that's not how FindFit substitutes the symbols.

As for NDSolve and NumberQ: these behaviors are documented in the Details sections and the examples, but you have to know where to look.

POSTED BY: Sjoerd Smit
Posted 7 years ago

Thank you, those corrections appear to make it work (though it is slow, so yes memoization probably should be used).

This should be in the documentation for NDSolve: "...changing the solution variables in NDSolve from {[Beta][t], [Gamma][t], [Delta][t], [Zeta][t], [Eta]} to {[Beta], [Gamma], [Delta], [Zeta], [Eta]}. Doing so will make NDSolve return functions instead of expressions in t."

The documentation for NumberQ and NumericQ should state the difference between the two functions that you mentioned: "It's usually better to use NumericQ for these kinds of matching patterns instead of NumberQ, since NumberQ has a few quirks that are often undesirable. For example, NumberQ[Pi] is False."

Thank you again.

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