matlab - Exponential curve fitting without the Curve Fitting toolbox? -
i have data points need fit exponential curve of form
y = b * exp(a/x)
(without of curve fitting toolbox).
what have tried far linearize model applying log, results in
log(y/b) = a/x log(y) = a/x + log(b)
i can write in form
y = ax + b
now, if neglect b
, able solve with
a = pseudoinverse (x) * y
but stuck values of b
...
fitting curve of form
y = b * exp(a / x)
to data points (xi, yi)
in least-squares sense difficult. cannot use linear least-squares that, because model parameters (a
, b
) not appear in affine manner in equation. unless you're ready use nonlinear-least-squares method, alternative approach modify optimization problem modified problem can solved using linear least squares (this process called "data linearization"). let's that.
under assumption b
, yi
's positive, can apply natural logarithm both sides of equations:
log(y) = log(b) + / x
or
a / x + log(b) = log(y)
by introducing new parameter b2
, defined log(b)
, becomes evident parameters a
, b2
appear in linear (affine, really) manner in new equation:
a / x + b2 = log(y)
therefore, can compute optimal values of parameters using least squares; have left construct right linear system , solve using matlab's backslash operator:
a = [1 ./ x, ones(size(x))]; b = log(y); params_ls = \ b;
(i'm assuming x
, y
column vectors, here.)
then, optimal values (in least-squares sense) modified problem given by:
a_ls = params_ls(1); b_ls = exp(params_ls(2));
although values not, in general, optimal original problem, "good enough" in practice. if needed, can use them initial guesses iterative nonlinear-least-squares method.
Comments
Post a Comment