Fit model to measured data without toolbox

조회 수: 4 (최근 30일)
J M
J M 2017년 10월 24일
답변: JM 2017년 11월 21일
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?

답변 (2개)

Alan Weiss
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
J M
J M 2017년 10월 24일
just read that fminsearch needs a scalar function..my bad. What are my options for a vector function as in my case?
Torsten
Torsten 2017년 10월 24일
편집: Torsten 2017년 10월 24일
"myModel (pVector, Lvector, G, H)" must return a vector of the same length as "mData".
This does not seem to be the case.
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.


JM
JM 2017년 11월 21일
Thanks Torsten. sorted now.

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by