How to choose solver, optimization or curve fitting?

Lets say I have 4 known curves in discrete values, S1,S2,S3 and S.
Supposedly S c1*S1 + c2*S2 + c3*S3 and C1+C2+C3 = 1, should I look into using curve fitting toolbox or the optimization toolbox to find the individual values C1, C2 and C3 that will give me a resultant curve that is closest to S?
I am new to this topic and would appreciate pointers to choosing the appropriate algorithm and how to incorporate the constraint C1+C2+C3 = 1 into the curve fit/otimization.
Thanks for any help that I can get.

 Risposta accettata

Matt J
Matt J il 2 Ago 2014
Modificato: Matt J il 2 Ago 2014
Eliminate c3 using c3=1-c1-c2, which reduces the relationship among your curves to,
c1*(S1-S3)+c2*(S2-S3)=(S-S3)
Now just use mldivide to find the least squares solution to the linear equations,
C=[S1(:)-S3(:), S2(:)-S3(:)]\(S(:)-S3(:));
c1=C(1)
c2=C(2);
c3=1-c1-c2;

4 Commenti

Im sorry that I was unclear in my question. S is not exactly equal to c1*S1 + c2*S2 + c3*S3. I expect S to differ from c1*S1 + c2*S2 + c3*S3 and would like to obtain the set of c1, c2 and c3 that minimizes the difference.
Matt J
Matt J il 2 Ago 2014
Modificato: Matt J il 2 Ago 2014
That doesn't affect my proposal at all. The same steps will give you a least squares solution if an exact one doesn't exist.
Sorry, I was mistaken about mldivide.
Matt J
Matt J il 4 Ago 2014
Modificato: Matt J il 4 Ago 2014
Happy that this answer works for you, but be mindful that it will not work if you plan to add bound constraints on c1,c2,c3 as you commented here. Eliminating c3 will convert the bound constraints to more complicated linear inequalities. You would have to use lsqlin as proposed by Ahmet to handle bounds and other linear inequality constraints

Accedi per commentare.

Più risposte (1)

You can either use a regularized regression function, or the optimization toolbox. I would guess optimization is the easier choice. Try lsqlin.

2 Commenti

Matt J
Matt J il 2 Ago 2014
Modificato: Matt J il 2 Ago 2014
I would use lsqlin if there are additional inequality constraints like c1>=0, c2>=0, c3>=0. Otherwise, it's way too simple a problem to warrant an iterative solution.
Thanks for all your suggestions. I do have some bounds for c1, c2 and c3.

Accedi per commentare.

Richiesto:

il 2 Ago 2014

Modificato:

il 4 Ago 2014

Community Treasure Hunt

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

Start Hunting!

Translated by