Fit model to measured data without toolbox
1 次查看(过去 30 天)
显示 更早的评论
nlinfit () in the stat toolboox is likely to what I want but I do not have the stat toolbox (nor do I have the optimization toolbox). I need to fit my model to measured data and extract model parameters. My model function ( myModel.m) is of the form
function Pout = myModel (pVector, Lvector, G, H)
k = 1;
for L = Lvector
P = AnotherFunction (pVector, L, G, H)
Pout(k) = P;
k=k+1;
end
where, pVector = [a, b, c, d, ...]'; contains the model parameters a, b, c, d...so on and L_vector is another vector of different length (= number of measured data points). G and H are constants for a given case (measurement). Pout is a vector of the same length as Lvector. I have tried the following using a cost function and fminsearch but throws an error which I am unable to resolve.
pGuess = [aGuess, bGuess, cGuesss, dGuess...]; % initial guess values for model paramters
G = SomeknownConstant; H = SomeknownConstant;
load MeasuredData.dat; mData = MeasuredData;
myCostFunc = @(pVector) sum ((myModel (pVector, Lvector, G, H) - mData).^2); % my COST function
opts = optimset('MaxFunEvals',40000, 'MaxIter',10000);
pVectorEstimated = fminsearch (myCostFunc,pGuess, opts);
This gives me an error when I use Lvector as a vector but runs when Lvector is single valued? Lvector needs to be a vector (with length equal to that of mData) as used in myModel.m in order to generate a model data close to the measured data, which then gets fitted to the measured data by varying the model parameters. Where am I going wrong? Are there alternatives to nlinfit e.g in fileexchange that I could use?
0 个评论
回答(2 个)
Alan Weiss
2017-10-24
I suggest that you try evaluating myCostFunc(pGuess) and seeing if the result is a scalar.
If it is a scalar, then please provide the exact error message (copy-paste) for more help, as we cannot tell what is happening from the incomplete information you have provided.
Alan Weiss
MATLAB mathematical toolbox documentation
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!