Fitting two arbitrary set of data without tool box
显示 更早的评论
Hello Matlab experts,
I have measurements of several vectors such that y(:,i) = [a1i,a2i,....ani]. This data set also includes measurement errors. Now I have a modeled solution such that ymodl =[b1, b2, b3,....bn]. I am trying to fit measurement data with modeled data using fminsearch as following:
function errprd=sumsqerror(fitparam,vecdata,datatraj)
a =fitparam(1);
b =fitparam(2);
ypred = a*vecdata +b;
errprd = sum((ypred-datatraj).^2);
fitfun = @(x)sumsqerror(x,evect,trajdata);
[bestx,errsumsqr, existflag, output] = fminsearch(fitfun,x);
My hypothesis suggests that one of columns of y measurement matrix should fit with modeled vector.
Though, I was unable to find a solution with this algorithm. I will highly appreciate if someone could tell me a better procedure (if there is any) to optimize a fitting of any arbitrary set of data.
Thank you.
Kind regards,
3 个评论
Walter Roberson
2018-10-19
For that particular ypred, a pure linear model, you can replace your entire code with a call to polyfit(evect, trajdata, 1)
Arun
2018-10-19
Walter Roberson
2018-10-19
You have
ypred = a*vecdata +b;
That is a plain y = a * x + b prediction, which polyfit(x,y,1) will calculate pretty quickly. Or more directly,
ab = [evect(:), ones(numel(evect),1] \ trajdata(:);
When I look at your data I would say, that a*x+b is a poor fit for the data -- but it is the model implemented by your ypred.
The data you display is pretty low quality. It looks like you only have 16 datapoints. I would guess maybe sum of three gaussians, maybe sum of four gaussians would be needed. That would require either 6 or 8 parameters. I would expect a low quality fit considering the small amount of data.
回答(1 个)
madhan ravi
2018-10-19
0 个投票
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!