Error in nlinfit function
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
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.
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!