nlinfit function, not enough input arguments

조회 수: 7 (최근 30일)
Srinivasan Rangan
Srinivasan Rangan 2018년 8월 11일
댓글: Star Strider 2018년 8월 11일
Dear All,
I am trying estimate 15 parameters using the following function: Parameters are x(1), x(2) ..... x(15)
function F = myfun(x,y,X)
F=(y - (1 + x(1)*(x(2)/0.0025662))*X(:,1) - (x(2)/x(3))*(sqrt(1-x(1)^2))*X(:,2) ...
- x( 4)*X(:, 3) - x(5)*X(:, 4)) - x( 6)*X(:, 5) - x( 7)*X(:, 6) - x(8)*X(:,7) ...
- x( 9)*X(:, 8) - x(10)*X(:, 9) - x(11)*X(:,10) - x(12)*X(:,11) ...
- x(13)*X(:,12) - x(14)*X(:,13) - x(15)*X(:,14);
end
X is a matrix with 18026 rows and 14 columns y is the dependent variable with 18026 rows and 1 column
I have 15 parameters to estimate and their starting values are defined by xstart (1 row by 15 columns)
When I specify x = nlinfit(X,y,myfun,xstart) in Matlab
I get the following error: Not enough input arguments.
Could you help and let me know how to change the specification?
best, Srinivasan

채택된 답변

Star Strider
Star Strider 2018년 8월 11일
Assuming that ‘y’ exists somewhere in your workspace, and since for MATLAB Statistics and Machine Learning Toolbox and Optimization Toolbox curve-fitting require two arguments, the first being the parameters and the second being the independent data, you would have to use this synatx:
@(x,X)myfun(x,y,X)
so your correct nlinfit call would be:
x = nlinfit(X,y,@(x,X)myfun(x,y,X),xstart)
although I cannot determine the reason you are using your dependent variable as an argument to your objective function. Since nlinfit will use it to fit your function, it is not necessary for you to use it specifically in your function. The best options is likely:
function F = myfun(x,X)
F=((1 + x(1)*(x(2)/0.0025662))*X(:,1) - (x(2)/x(3))*(sqrt(1-x(1)^2))*X(:,2) ...
- x( 4)*X(:, 3) - x(5)*X(:, 4)) - x( 6)*X(:, 5) - x( 7)*X(:, 6) - x(8)*X(:,7) ...
- x( 9)*X(:, 8) - x(10)*X(:, 9) - x(11)*X(:,10) - x(12)*X(:,11) ...
- x(13)*X(:,12) - x(14)*X(:,13) - x(15)*X(:,14);
end
and then:
x = nlinfit(X,y,@myfun,xstart)
  댓글 수: 2
dpb
dpb 2018년 8월 11일
Good catch on the functional, SS...
Star Strider
Star Strider 2018년 8월 11일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

dpb
dpb 2018년 8월 11일
편집: dpb 2018년 8월 11일
x = nlinfit(X,y,myfun,xstart)
Is passing the function as an argument instead of the function handle; hence it's missing its argument list which is what is generating the error for lack of inputs.
x = nlinfit(X,y,@myfun,xstart); % NB the ampersand...

Srinivasan Rangan
Srinivasan Rangan 2018년 8월 11일
Dear dpb,
Thanks very much. The error persists.
x = nlinfit(X,y,@myfun,xstart);
Error using nlinfit (line 213)
Error evaluating model function 'myfun'.
Caused by: Not enough input arguments.
Would you have other suggestions
best, Srini

Srinivasan Rangan
Srinivasan Rangan 2018년 8월 11일
Thank you very much Star Strider. That worked!

카테고리

Help CenterFile Exchange에서 Correlation Models에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by