Exponential curve fitting without the Curve Fitting toolbox?

后端 未结 2 1744
别那么骄傲
别那么骄傲 2021-01-25 07:54

I have some data points to which I need to fit an exponential curve of the form

y = B * exp(A/x)

(without the help of Curve Fitting Toolbox).

2条回答
  •  借酒劲吻你
    2021-01-25 08:10

    Fitting a curve of the form

    y = b * exp(a / x)
    

    to some data points (xi, yi) in the least-squares sense is difficult. You cannot use linear least-squares for that, because the model parameters (a and b) do not appear in an affine manner in the equation. Unless you're ready to use some nonlinear-least-squares method, an alternative approach is to modify the optimization problem so that the modified problem can be solved using linear least squares (this process is sometimes called "data linearization"). Let's do that.

    Under the assumption that b and the yi's be positive, you can apply the natural logarithm to both sides of the equations:

    log(y) = log(b) + a / x
    

    or

    a / x + log(b) = log(y)
    

    By introducing a new parameter b2, defined as log(b), it becomes evident that parameters a and b2 appear in a linear (affine, really) manner in the new equation:

    a / x + b2 = log(y)
    

    Therefore, you can compute the optimal values of those parameters using least squares; all you have left to do is construct the right linear system and then solve it using MATLAB's backslash operator:

    A = [1 ./ x, ones(size(x))];
    B = log(y);
    params_ls = A \ B;
    

    (I'm assuming x and y are column vectors, here.)

    Then, the optimal values (in the least-squares sense) for the modified problem are given by:

    a_ls = params_ls(1);
    b_ls = exp(params_ls(2));
    

    Although those values are not, in general, optimal for the original problem, they are often "good enough" in practice. If needed, you can always use them as initial guesses for some iterative nonlinear-least-squares method.

提交回复
热议问题