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
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?
채택된 답변
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;
댓글 수: 13
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
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!