How to choose solver, optimization or curve fitting?
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Matt J
on 2 Aug 2014
Edited: Matt J
on 2 Aug 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 Comments
Matt J
on 4 Aug 2014
Edited: Matt J
on 4 Aug 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
More Answers (1)
Ahmet Cecen
on 2 Aug 2014
You can either use a regularized regression function, or the optimization toolbox. I would guess optimization is the easier choice. Try lsqlin.
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!