Error in nlinfit function

조회 수: 2 (최근 30일)
Harjot Singh Saluja
Harjot Singh Saluja 2021년 4월 28일
답변: Pratyush Roy 2021년 5월 12일
Hello,
I have a dataset in which I have three independent variables in a function to give an output, the code for which is given as follows:
ip = [791.3080768 27.77748384 0.022016716
763.1277705 24.17306411 0.020330783
616.5766311 11.13145056 0.012707747
448.0010846 3.698850278 0.011639681
];
op = [28;23.2;10;4.3];
fun = @(c,x) c(1)* ip(:,2).^c(2) .* exp(ip(:,1)./c(3)) .* ip(:,3).^c(4);
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(ip,op,fun,rand(4,1));
When I try to run it in MATLAB, I get the following error: "The function you provided as the MODELFUN input has returned Inf or NaN values."
I am not sure why is this happening, I have checked the input data in "ip" but can't seem to find the solution. It would be really great if someone here can help me with it.
Thanks in advance!

답변 (1개)

Pratyush Roy
Pratyush Roy 2021년 5월 12일
Hi Harjot,
The model function fun requires two input arguments, a coefficient vector and an array X—in that order—and return a vector of fitted response values. As per the code snippet shared above, the co-efficient values have not been passed to the model function. For a good non-linear fit, it should be ensured that proper co-efficient values in the form of an array c has been passed to the model function.
You can refer to the documentation link for nlinfit for more information.
Hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by