Matlab nonlinear fitting function - nlinfit

The most commonly used nonlinear fitting function is still polynomial fitting. One day, my student suddenly asked me about the nlinfit function, and then directly queried the official documentation of matlab. It turns out that this function can also be used for nonlinear functions. Let’s take a look at the official matlab Description from the documentation:

English? It doesn't matter, let's take a look at the Chinese usage:

beta = nlinfit(X, Y, modelfun, beta0)

beta: the coefficient of the estimated nonlinear function

modelfun: the specified nonlinear function to be fitted

beta0: the initial value of the regression coefficient

[beta, R, J, CovB, MSE, ErrorModelInfo] = nlinfit(___) 

R: Residual

J: modelfun Jacobian matrix

CovB: Estimate variance-covariance matrix

MSE: mean square error

ErrorModelInfo: Error information between the fitting function and the actual value Y

The middle two are not used much, if necessary, please refer to the help documentation by yourself.

Let's explain it in detail with an example: 

Functions that need to be fitted:

Initial value: [-1 1 -1 1 1] 

code show as below:

x=1:16;
y=[4 6.4 8 8.8 9.22 9.5 9.7 9.86 10 10.2 10.32 10.42 10.5 10.55 10.58 10.6];
y1=@(b,t) b(1)*exp(-t/b(2))+b(3)*exp(-t/b(4))+b(5);
b0=[-1 1 -1 1 1];%初始参数
[beta,R,J,CovB, MSE,ErrorModelInfo]=nlinfit(x,y,y1,b0)%所求出的回归系数
xp=1:0.1:16;
yp=y1(beta,xp);
plot(x,y,'.k',xp,yp,'r')

result:

 

It can be seen from the figure that the fitting effect is good. 

This is the end of the introduction of this function, please refer to the official help documentation for more information.

Guess you like

Origin blog.csdn.net/m0_64087341/article/details/126807477