linear combination of curves to match a single curve

8 次查看(过去 30 天)
I have measured 3 different data sets with the same amount of x variables. Two of these data sets are reference materials (called ref1 and ref2). Now I want to write a routine in matlab to fit the third data set by varying the weight of the two other data sets to get an idea of the contribution of ref1 and ref2 to the third signal, like:
y=w1*ref1+w2*ref2
in some cases there is one boundary condition that w1+w2=1
Is it possible to get a rough idea about the error of w1 and w2?

回答(1 个)

dbmn
dbmn 2017-2-20
This can be done nicely in a least squares approach - especially with Matlab mldivide operator.
I will give you an example
% Generate Test Data
x1 = rand(10,1);
x2 = rand(10,1);
y = x1 + 2*x2;
% Solve for w1 and w2
w = [x1 x2]\y
If you have additional conditions such as w2 = 1 - w1 (x1+x2=1) just add those to your equation and solve
f.ex. y = w1*x1 + w2*x with w2 = 1 - w1
y = w1x1 +(1-w1)x2
y - x2 = y_hat = w1 x_hat = w1 (x1-x2)
And then use the first solution

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by