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

11 visualizaciones (últimos 30 días)
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 comentarios
Star Strider
Star Strider el 10 de Ag. de 2012
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 el 10 de Ag. de 2012
Hello,
Yes, the fi(x) are vectors of the same length y, the data I would like to decompose.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 10 de Ag. de 2012
Editada: Star Strider el 10 de Ag. de 2012
‘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 comentarios
Chris
Chris el 11 de Ag. de 2012
I have finished calculating the confidence limits on the fit parameters...let me know if you want the full script.
Star Strider
Star Strider el 11 de Ag. de 2012
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.

Iniciar sesión para comentar.

Más respuestas (1)

Teja Muppirala
Teja Muppirala el 10 de Ag. de 2012
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 comentarios
Tom Lane
Tom Lane el 10 de Ag. de 2012
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 el 10 de Ag. de 2012
Editada: Chris el 10 de Ag. de 2012
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by