Exponential curve fitting without the Curve Fitting toolbox?

后端 未结 2 1743
别那么骄傲
别那么骄傲 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:24

    Doing the log transform then using linear regression should do it. Wikipedia has a nice section on how to do this: http://en.wikipedia.org/wiki/Linear_least_squares_%28mathematics%29#The_general_problem

        %MATLAB code for finding the best fit line using least squares method
        x=input('enter a')                      %input in the form of matrix, rows contain points
            a=[1,x(1,1);1,x(2,1);1,x(3,1)]          %forming A of Ax=b
            b=[x(1,2);x(2,2);x(3,2)]                %forming b of Ax=b
            yy=inv(transpose(a)*a)*transpose(a)*b   %computing projection of matrix A on b, giving x
        %plotting the best fit line
          xx=linspace(1,10,50);
          y=yy(1)+yy(2)*xx;
          plot(xx,y)
             %plotting the points(data) for which we found the best fit line
         hold on
            plot(x(2,1),x(2,2),'x')
         hold on
            plot(x(1,1),x(1,2),'x')
         hold on
            plot(x(3,1),x(3,2),'x')
         hold off
    

    I'm sure the code can be cleaned up, but that's the gist of it.

提交回复
热议问题