Pietair
Pietair

Reputation: 406

Nonlinear Model Fit

Good day,

I have got the following code in Matlab:

ds1 =

    2.0709   -3.0379
    3.1447   -1.4320
    4.0650   -2.5355

modelfun = @(b,w)(b(1)*10.^w+b(2));

beta0 = [1 1];

mdl = NonLinearModel.fit(ds1,modelfun,beta0);

I am trying to create a NonLinearModel fit to the equation: y = beta(1)*10^(w)+beta(2), however I end up with the following error:

Error using NonLinearModel.fit (line 837) Model definition and initial values for model coefficients must be provided.

Any ideas?

Upvotes: 0

Views: 853

Answers (1)

duffymo
duffymo

Reputation: 309028

Is that model a requirement? I'm not sure it'd be my first choice.

Start by plotting the data. (Not much of it, is there?) A simple 2nd order polynomial will be an exact fit, since you have three points.

y = c0 + c1*x + c2*x^2

Or may a transformation by taking the base 10 log of both sides will work better for you.

There's no need for a non-linear model here. But if you did need one, it's common knowledge that non-linear solutions need a starting point. They try to step to the true solution, if there is one, in iterative fashion.

There may not be a solution, or you might choose a bad starting point, or the step size might too small to finish in time, or too large and step right over the answer you want.

All these are what make non-linear problems so much harder than linear ones.

Upvotes: 1

Related Questions