Error in nlinfit function

2 Ansichten (letzte 30 Tage)
Harjot Singh Saluja
Harjot Singh Saluja am 28 Apr. 2021
Beantwortet: Pratyush Roy am 12 Mai 2021
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!

Antworten (1)

Pratyush Roy
Pratyush Roy am 12 Mai 2021
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!

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by