Numerical fitting to model that has Integral with no analytical solution
5 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
Neil Guertin
2017-8-10
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.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!