How can I fit data as sum of multiple data?

2 views (last 30 days)
Shiran
Shiran on 17 Aug 2015
Edited: John D'Errico on 17 Aug 2015
Hello, I have 3 graphs and I want to fit the 3rd graph as a sum of the other where the fitting parameters are the weights (no function fitting).
For example, assume I have 3 vectors A,B and C and I want to do fitting to vector C such that -
C= a*b1* A + (1-a)*c*b2* B + (1-a)(1-c)*b2* B
here my fitting parameters are - a, b1, b2 and c.
Any ideas?? Any input on the matter would be highly appreciated. Thanks, Shiran

Answers (2)

Star Strider
Star Strider on 17 Aug 2015
Edited: Star Strider on 17 Aug 2015
If I understand your Question correctly, this would work:
C = [A(:) B(:) B(:)] * [(a*b1); ((1-a)*c*b2); ((1-a)(1-c)*b2)];

John D'Errico
John D'Errico on 17 Aug 2015
Edited: John D'Errico on 17 Aug 2015
You have vectors A,B,C, and UNKNOWN parameters a,b1,b2,c.
I'm sorry, but it cannot be solved, at least not uniquely. To understand why, we need to do just a wee bit of pencil and paper algebra.
C = a*b1* A + (1-a)*c*b2* B + (1-a)(1-c)*b2* B
Lets rewrite it, because B appears twice in there.
C = a*b1* A + [(1-a)*c*b2 + (1-a)(1-c)*b2]* B
As well, c is in those same terms. When we combine the coefficients,
C = a*b1* A + (1-a)*b2* B
You should see that c goes away completely. COMPLETELY. The value of c is COMPLETELY irrelevant. So, I suppose if it pleases you, lets just choose
c = 42
as that is supposed to be the answer to everything - life, the universe, everything. Personally, I like
c = 17
better, but we all have our silly preferences.
Regardless, in the end, we came down to this:
C = a*b1* A + (1-a)*b2* B
where a,b1,b2 are unknown constants, and A,B,C are vectors. The fact is though, we should realize that in fact, the above expression is equivalent to:
C = u*A + v*B
where u and v are unknowns.
We can solve for u and v easily enough, as long as A,B,C are vectors of the same length, and that length is at least 2. (By the way, this next part is the only one where the use of MATLAB is of any value.)
uv = [A(:),B(:)]\C(:);
u = uv(1);
v = uv(2);
Ok, so now we can go back, and see if it is possible to recover a,b1,b2.
u = a*b1
v = (1-a)*b2
Hmm. We have two equations, and three unknowns. Yes, we chose our favorite value for c already, but still we are stuck. It is IMPOSSIBLE to uniquely choose values for all three of a,b1,b2 here, given only two pieces of information.
I'm sorry, but the laws of mathematics are not particularly friendly, and they are quite firm. You can choose ANY value (except zero) for any one of those parameters, and only then can you solve uniquely for the other two parameters.
For example, let a = 0.5, and then we get b1 and b2 rather simply.
b1 = 2*u
b2 = 2*v
What you need to understand is that regardless of how many data points you have in the vectors A,B,C, there is simply insufficient information to solve for 4 parameters. In fact, there is sufficient information to solve uniquely for only two of those parameters, with two essentially undetermined constants.
Now, you DID use the words "for example" in your question. Does that mean this is not your real problem? Maybe. I cannot know. If you have a valid problem, with uniquely solvable coefficients, then you should show what it is! I cannot help you if you don't show the real problem. Or perhaps what you did not understand how to solve some rather general problem. I cannot know. Every problem is usually subtly different, although there are often some features in common.

Tags

Community Treasure Hunt

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

Start Hunting!