Numerical fitting to model that has Integral with no analytical solution
이전 댓글 표시
I'm attempting to fit a model to my numerical dataset. Unfortunately, the model contains an integral that cannot be solved analytically, but it can be solved numerically using integral function. The response is g_a and the input is T. However, I am getting the following error.
Error using nlinfit (line 205) Error evaluating model function '@(b,y)b(1)./Beta*integral(@(y)f(y,b),1273,T)'.
Error in NonLinearModel/fitter (line 1122) [model.Coefs,~,J_r,model.CoefficientCovariance,model.MSE,model.ErrorModelInfo,~] = ...
Error in classreg.regr.FitObject/doFit (line 220) model = fitter(model);
Error in NonLinearModel.fit (line 1430) model = doFit(model);
Error in fitnlm (line 94) model = NonLinearModel.fit(X,varargin{:});
Error in test (line 12) mdl=fitnlm(g_a,T,modelfun,beta0);
Caused by: Error using integral (line 85) A and B must be floating-point scalars.
A=76540300000;
E=440.156;
Beta=1;
R=8.314e-3;
f=@(y,b) exp(-b(2)./(R*y));
modelfun = @(b,y) b(1)./Beta*integral(@(y)f(y,b),1273,T);
beta0=[76540300000 440];
mdl=fitnlm(g_a,T,modelfun,beta0);
답변 (1개)
Neil Guertin
2017년 8월 10일
0 개 추천
There are many things here that could be causing issues:
The error you see is because the third argument to the integral function (xmax) must be a scalar. You have given T, which I assume is a matrix.
Also, you have flipped the first two arguments of fitnlm. The first should be the input matrix T, the second should be the response vector g_a.
modelfun must be a vectorized function, meaning that its parameter y is a matrix where each row corresponds to an observation, and it returns a column vector where each row is the response from that observation. You may find it easier to use a local or a nested function instead of an anonymous function.
Finally, the parameter y of modelfun is shadowed by the parameter y of the integral function. This would be another reason to use a local or a nested function, or you could simply rename one of the parameters.
댓글 수: 1
laurent jalabert
2023년 2월 17일
is there any update regarding the solution of this problem ?
I have a similar problem, even more complicated using a vector, constant parameter, and an integral function as a fitting model. It is a pure hurdle,but it is easily solved in Mathematica. However, I did not succeeded to translate from Mathematica to Matlab. I do not understand how to do that.
카테고리
도움말 센터 및 File Exchange에서 Multibody Modeling에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!