Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Non linear model fitting with an integral model

236 views
Skip to first unread message

Bill Rowe

unread,
Mar 13, 2012, 4:07:51 AM3/13/12
to
On 3/12/12 at 4:07 AM, juan.b...@gmail.com (Juan Baselga) wrote:

>Hello, I'm new user of Mathemetica. I'm trying to fit data to a
>model, that is defined by an integral, using NonlinearModelFit. The
>integral contains the parameter I'm looking for. When I set a
>particular value for the parameter, NIntegrate works well giving an
>estimate of the integral value; but when I define the model within
>the fitting algorithm, the integral cannot be numerically evaluated
>since it contains the non-numerical parameter giving the "inumr"
>error message. Do anyone know how to fit data with model parameters
>contained in an integral that must be numerically evaluated?

It is difficult to know exactly what the issue is that you are
having when you don't provide code showing what you are doing. I
will offer a guess.

The typical problem with using NIntegrate in the fashion you
describe is Mathematica attempts to perform the integration
before the fitting routing supplies numerical values for the key
variables. The solution is to define the function being
integrated so that it only evaluates with numerical input.

For example:

If I define f as

f[x_]:= x^2

This will evaluate for any x including symbolic values. As a
result (depending on details of your code) Mathematica can
attempt to evaluate this before x is given a numeric value. But
by defining f as:

f[x_?NumericQ]:=x^2

Mathematica will only evaluate f when x is given a numeric
value. My suggestion would be to add the pattern test ?NumericQ
to you function definitions and see if this fixes your problem.
If it doesn't you will need to supply more details of your
specific problem.


Darren Glosemeyer

unread,
Mar 13, 2012, 4:11:56 AM3/13/12
to
On 3/12/2012 4:07 AM, Juan Baselga wrote:
> Hello, I'm new user of Mathemetica. I'm trying to fit data to a model, that is defined by an integral, using NonlinearModelFit. The integral contains the parameter I'm looking for. When I set a particular value for the parameter, NIntegrate works well giving an estimate of the integral value; but when I define the model within the fitting algorithm, the integral cannot be numerically evaluated since it contains the non-numerical parameter giving the "inumr" error message. Do anyone know how to fit data with model parameters contained in an integral that must be numerically evaluated?
>

The place to start is using a definition for the model that will only
evaluate when all quantities that need to be numeric are numeric.
Compare the results when using f1 and f2 in the following:

data = Table[{i, i^2/2}, {i, 5}];

f1[a_, y_] := NIntegrate[a*x, {x, 0, y}]

f1[a, y]

NonlinearModelFit[data, f1[a, y], a, y];

f2[a_?NumericQ, y_?NumericQ] := NIntegrate[a*x, {x, 0, y}]

f2[a, y]

NonlinearModelFit[data, f2[a, y], a, y]


?NumericQ restrictions like those in f2 are most likely what you need in
your example.

Darren Glosemeyer
Wolfram Research

0 new messages