How can I do non-linear fitting on a model defined implicitly?
조회 수: 7 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2014년 4월 11일
편집: MathWorks Support Team
2021년 2월 2일
I would like to use the "nlinfit" function to do nonlinear regression on a model that is defined implicitly:
y = model(x,y,params)
The documentation for "nlinfit" explains how to fit a model defined explicitly:
y = model(x,params)
Is there a way to specify my model so that I can use "nlinfit" to estimate its parameters? Do you have other functions that I could use with my implicit model?
채택된 답변
MathWorks Support Team
2014년 4월 11일
1. Using "nlinfit"
The "nlinfit" function expects a response vector "Y" and a function of unknown parameters. Simply encapsulate the implicit model in a function of the form:
0 = y - model(x,y,beta)
The response vector to be passed to "nlinfit" becomes
Y = zeros(size(y));
The new predictor array now contains both the old predictor variables and the old responses packed together in one array:
X = [x,y];
and the new model is specified by the anonymous function
modelfun = @(beta,X) ( X(:,2) - model(X(:,1),X(:,2),beta) );
where "model" is the implicit model with inputs "x" and "y", output "y", and parameterized by the (unknown) parameter vector "beta".
Finally, use "nlinfit" with an initial guess "beta0" as follows:
beta = nlinfit(X,Y,modelfun,beta0)
2. Using "lsqnonlin"
Alternatively, you could achieve the same results with the "lsqnonlin" function of the Optimization Toolbox.
The "lsqnonlin" function tries to solve a least-squares equation of the form
min_x { f_1(x)^2 + f_2(x)^2 + ... + f_n(x)^2 }
for an unknown vector "x".
In the case of fitting an implicit model, the vector "x" would be the vector of unknown parameters "beta" of the implicit model and f_i(x) would be:
f_i(beta) = y_i - model(x_i,y_i,beta)
where "X=[x_i]" are the predictors and "Y=[y_i]" are the responses used to fit the model.
However, "lsqnonlin" takes as input argument a handle to a function of only 1 argument (the parameters). You would have to pass extra parameters (in this case, the predictors and responses) by using an anonymous function. Assume your implicit model is defined in a function file called "model". Then, "modelfun" is a handle to an anonymous function defined as:
modelfun = @(beta) ( Y - model(X,Y,beta) );
where "Y" is the vector of responses, "X" is the vector of predictors, and "beta" is the vector of unknown parameters.
With an initial guess "beta0", call "lsqnonlin" as follows:
beta = lsqnonlin(modelfun,beta0)
댓글 수: 1
Abhishek Pandey
2016년 5월 13일
편집: MathWorks Support Team
2021년 2월 2일
Hi Srikanth! If you are still facing issues with this, feel free to contact MathWorks Technical Support. They should be able to help you with this.
- Abhishek
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!