Navigation

Operators and Keywords

Function List:

C++ API

Function File: [p, fy, cvg, outp] = nonlin_curvefit (f, pin, x, y)

Function File: [p, fy, cvg, outp] = nonlin_curvefit (f, pin, x, y, settings)

Frontend for nonlinear fitting of values, computed by a model function, to observed values.

Please refer to the description of nonlin_residmin. The only differences to nonlin_residmin are the additional arguments x (independent values, mostly, but not necessarily, an array of the same dimensions or the same number of rows as y) and y (array of observations), the returned value fy (final guess for observed values) instead of resid, that the model function has a second obligatory argument which will be set to x and is supposed to return guesses for the observations (with the same dimensions), and that the possibly user-supplied function for the jacobian of the model function has also a second obligatory argument which will be set to x.

See also: nonlin_residmin.

Demonstration 1

The following code

  ## Example for linear inequality constraints
  ## (see also the same example in 'demo nonlin_residmin')

  ## independents and observations
  indep = 1:5;
  obs = [1, 2, 4, 7, 14];
  ## model function:
  f = @ (p, x) p(1) * exp (p(2) * x);
  ## initial values:
  init = [.25; .25];
  ## linear constraints, A.' * parametervector + B >= 0
  A = [1; -1]; B = 0; # p(1) >= p(2);
  settings = optimset ("inequc", {A, B});

  ## start optimization
  [p, model_values, cvg, outp] = nonlin_curvefit (f, init, indep, obs, settings)

Produces the following output

p =

   0.62034
   0.62034

model_values =

    1.1536    2.1451    3.9891    7.4179   13.7941

cvg =  3
outp =

  scalar structure containing the fields:

    niter =  7

Package: optim