Error Using fitnlm Function

1 回表示 (過去 30 日間)
Ricardo Gutierrez
Ricardo Gutierrez 2021 年 3 月 19 日
回答済み: Star Strider 2021 年 3 月 19 日
function regresion_parametros_secador
clc, clear, clear all
TR =[0.422103409 0.42981426 0.437540563 0.445266867 0.45299317 0.460719473 0.468445777 0.47617208 0.483898384 0.491624687 0.499350991 0.507077294 0.514803597 0.522529901 0.530256204 0.537982508 0.545708811 0.553435115 0.561161418 0.568887721 0.576614025 0.592066632 0.607519238 0.622971845 0.638424452 0.653877059 0.669329666 0.684782273 0.70023488 0.715687486 0.731140093 0.7465927 0.762045307 0.777497914 0.792950521 0.808403128 0.823855734 0.839308341 0.854760948 0.870213555 0.885666162 0.901118769 0.916571376 0.932023982 0.947476589 0.962929196 0.978381803 0.99383441 0.99993819];
HFG =[2500.9 2489.1 2477.2 2465.3 2453.5 2441.7 2429.8 2417.9 2406.0 2394.0 2382.0 2369.8 2357.6 2345.4 2333.0 2320.6 2308.0 2295.3 2282.5 2269.5 2256.4 2229.7 2202.1 2173.7 2144.2 2113.7 2081.9 2048.8 2014.2 1977.9 1939.7 1899.7 1857.3 1812.7 1765.4 1715.1 1661.6 1604.4 1543.0 1476.7 1404.6 1325.7 1238.4 1140.1 1027.3 892.7 719.8 443.8 0.0];
modelfun = @(p,HFG) (exp((p(1)+p(2)*(log(1./TR))^0.1+p(3)/TR.^2+p(4)/TR.^3+p(5)/TR.^4)^0.5));
beta0 = [0 53.63746882 0.01601773 0.031311254 0.071298912];
mdl = fitnlm(TR,HFG,modelfun,beta0)
end
%ERROR MESSAGE%
Error using nlinfit (line 205)
Error evaluating model function
'@(p,HFG)(exp((p(1)+p(2)*(log(1./TR))^0.1+p(3)/TR.^2+p(4)/TR.^3+p(5)/TR.^4)^0.5))'.
Error in NonLinearModel/fitter (line 1123)
nlinfit(X,y,F,b0,opts,wtargs{:},errormodelargs{:});
Error in classreg.regr.FitObject/doFit (line 94)
model = fitter(model);
Error in NonLinearModel.fit (line 1430)
model = doFit(model);
Error in fitnlm (line 94)
model = NonLinearModel.fit(X,varargin{:});
Error in regresion_parametros_secador (line 14)
mdl = fitnlm(TR,HFG,modelfun,beta0)
Caused by:
Error using ^
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise
power.
>>

採用された回答

Star Strider
Star Strider 2021 年 3 月 19 日
Use element-wise operations on every applicable operation in ‘modelfun’ and transpose ‘modelfun’ to return a column vector, and it works:
TR =[0.422103409 0.42981426 0.437540563 0.445266867 0.45299317 0.460719473 0.468445777 0.47617208 0.483898384 0.491624687 0.499350991 0.507077294 0.514803597 0.522529901 0.530256204 0.537982508 0.545708811 0.553435115 0.561161418 0.568887721 0.576614025 0.592066632 0.607519238 0.622971845 0.638424452 0.653877059 0.669329666 0.684782273 0.70023488 0.715687486 0.731140093 0.7465927 0.762045307 0.777497914 0.792950521 0.808403128 0.823855734 0.839308341 0.854760948 0.870213555 0.885666162 0.901118769 0.916571376 0.932023982 0.947476589 0.962929196 0.978381803 0.99383441 0.99993819];
HFG =[2500.9 2489.1 2477.2 2465.3 2453.5 2441.7 2429.8 2417.9 2406.0 2394.0 2382.0 2369.8 2357.6 2345.4 2333.0 2320.6 2308.0 2295.3 2282.5 2269.5 2256.4 2229.7 2202.1 2173.7 2144.2 2113.7 2081.9 2048.8 2014.2 1977.9 1939.7 1899.7 1857.3 1812.7 1765.4 1715.1 1661.6 1604.4 1543.0 1476.7 1404.6 1325.7 1238.4 1140.1 1027.3 892.7 719.8 443.8 0.0];
modelfun = @(p,HFG) (exp(sqrt(p(1)+p(2).*(log(1./TR)).^0.1+p(3)./TR.^2+p(4)./TR.^3+p(5)./TR.^4))).';
beta0 = [0 53.63746882 0.01601773 0.031311254 0.071298912];
mdl = fitnlm(TR,HFG,modelfun,beta0)
producing:
mdl =
Nonlinear regression model:
y ~ F(p,HFG)
Estimated Coefficients:
Estimate SE tStat pValue
________ _______ _______ __________
b1 -5.3764 0.53639 -10.023 6.2155e-13
b2 80.604 1.2895 62.51 1.2803e-44
b3 -12.018 1.5173 -7.9205 5.2486e-10
b4 6.8052 1.0612 6.413 8.3294e-08
b5 -1.1397 0.2096 -5.4375 2.2468e-06
Number of observations: 49, Error degrees of freedom: 44
Root Mean Squared Error: 12.4
R-Squared: 1, Adjusted R-Squared 1
F-statistic vs. zero model: 2.6e+05, p-value = 3.84e-97
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by