Linear approximation of data set's points.
57 views (last 30 days)
Show older comments
i have a data set (x,y) that i have to approximate with a piecewise linear function, such that lower and upper bounds are satisfied. the image show what's the result I would like to achieve (in red the data set's points; in grey, the linear continuous approximation i would like to describe)image of result to achieve.
Using Matlab, i've divided all points in groups (one for every linear segment) and approximated every linear segment, with needed constraints, in the sense of least squares. But i need to have a continuous function and I am stuck in solving the problem. There's someone that have an idea of what i can do to solve the problem?
thanks in advance to everyone
2 Comments
John D'Errico
on 10 Apr 2021
Edited: John D'Errico
on 10 Apr 2021
You could have saved us some time if you actually said this was what you want to do, instead of saying you wanted a continuous piecewise linear approximation. No. You cannot use that tool to create a curve that is partly circular arcs, and partly linear segments.
It looks like you have asked this question again anyway. Please don't ask it a third time.
Answers (1)
John D'Errico
on 8 Apr 2021
Edited: John D'Errico
on 8 Apr 2021
Don't do it that way!!!!!!! You cannot achieve a continuous piecewise linear function that way. Instead, use a tool designed to solve that problem. For example:
x = rand(1,100);
y = sin(pi*x);
slm = slmengine(x,y,'knots',0:0.2:1,'degree','linear','plot','on');
So piecewise linear segments, fit using least squares. Breaks at the points 0:.2:1.
You can find my SLM toolbox for free download from the file exchange, here:
You can use the resulting structure, evaluating the function, or you could even extract the linear segments.
See Also
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!