curve fitting with numeric array instead of analytic form for function of x

11 次查看(过去 30 天)
Hello,
Sorry if this is a silly question, but I've been searching through the help documentation and I've been unable to find an answer. Does MATLAB have the ability to do linear least squares fitting of the type y = a*f1(x) + b*f2(x) + ..., where fi(x) are numerically defined functions of the independent variable? I have f1, f2, f3, and f4 defined in vectors as the normalized (to maximum value) results of source signal measurements. I have another set of signal measurements that I want to 'decompose' into a linear sum of the four sources, with amplitudes determined by least squares.
I've found that I can define functions of 'x' and use the matlab function 'fit' with no problem, but I'm unable to write down an analytic functional form for this type of model, so I don't think the curve fitting toolbox will be of much use. Does anyone have any suggestions?
Thanks a lot,
Chris
  2 个评论
Star Strider
Star Strider 2012-8-10
Do your functions f1(x) ... fi(x) produce vectors equal to length(y) (assuming y is a vector and not a matrix), or are they nonlinear functions that have to be evaluated during the parameter estimation process?
Chris
Chris 2012-8-10
Hello,
Yes, the fi(x) are vectors of the same length y, the data I would like to decompose.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2012-8-10
编辑:Star Strider 2012-8-10
‘Yes, the fi(x) are vectors of the same length y, the data I would like to decompose.’
In that situation, this seems to me a multiple linear regression problem. If your matrix of f(*) vectors is F, your vector of parameters a, b, ... is P, then your system becomes (with the appropriate dimensions of F):
y = F*P
and the solution:
P = F\y;
A;though you may need to augment F with a constant vector such as:
F1 = [ones(size(F,1) F];
and then:
P = F1\y;
A more formal implementation of this — with statistics — is regress in the Statistics Toolbox.
  13 个评论
Chris
Chris 2012-8-11
I have finished calculating the confidence limits on the fit parameters...let me know if you want the full script.
Star Strider
Star Strider 2012-8-11
I would appreciate it, yes.
You might consider writing it up formally as a function, documenting it internally, and submitting it to the MATLAB File Exchange. (I believe the FEX has some suggestions on how best to do that. I haven't checked, since I haven't submitted any files in a while.) It seems to be needed. Even though lscov exists, not everyone may have the Statistics Toolbox, or want to go through everything you had to do to re-create your function.

请先登录,再进行评论。

更多回答(1 个)

Teja Muppirala
Teja Muppirala 2012-8-10
If I understand you correctly, then I think all you need is the "backslash" operator. Just like this:
x = (0:0.1:10)';
f1 = sin(x);
f2 = exp(x/10);
f3 = 3./(1+x);
y = 3*f1 - 4*f2 + 8*f3 + 1*randn(size(x));
plot(x,y);
estimated_coeffs = [f1 f2 f3]\y
hold on;
plot(x,[f1 f2 f3]*estimated_coeffs,'r');
  3 个评论
Tom Lane
Tom Lane 2012-8-10
Teja's example calculated f1-f3 as expressions. I would think you could calculate them by fetching them out of the table, and still carry out the backslash operation that he recommends.
Chris
Chris 2012-8-10
编辑:Chris 2012-8-10
Yes, it is simple to get the 'best fit' coefficients through the backslash operator. This is basically how I am currently performing the fit. However, MATLAB already has functionality for evaluating goodness of fit (also simple) and confidence intervals for the fitted parameters(not as simple). I was hoping to be able to make use of that functionality, instead of finding the bounds of the hyperdimensional ellipse of the chi-square surface myself, in order to find confidence limits on my fitted parameters.

请先登录,再进行评论。

类别

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