In the documentation I found a nice idiom which allows me to do model fitting with interpolating functions. I think this kind of thing is amazing and a credit to the utility of an environment like Mathematica. It goes like this:
model[a_?NumberQ, b_?NumberQ, c_?NumberQ] :=
Module[{y, x},
First[y /.
NDSolve[{y''[x] + a y[x] == 0, y[0] == b, y'[0] == c},
y, {x, 0, 10}]]]
nlm = NonlinearModelFit[data, model[a, b, c][x], {a, b, c}, x]
I think I understand how this works but my question is this: what is the significance of the pattern object ?NumberQ when model is first defined? For example my initial implementation of this was as follows:
model[a_ ,t_] :=
Module[{y, x},
First[y /.
NDSolve[{a(y'[x] t + y[x] == vtest, y[0] == 0},
y, {x, 0, end}]
]]
This is a just a different diff eq where vtest and end are given values ahead of time. But if I run this through the NonlinearModelFit without the ?NumberQ pattern on the initial model definition I get an NDSolve error saying that it encountered a non-numerical derivative at x$16212==0. I know how to avoid this I just don't understand why it doesn't work. Any help understanding what this error message indicates and what the role of the pattern object is would be much appreciated.
NonlinearModelFit
does not have anyHold*
attributes, so your code evaluatesmodel[a, b, c]
with symbolic arguments beforeNonlinearModelFit
"sees" it. $\endgroup$