Skip to main content
1-Visitor
October 16, 2019
Question

Curve fitting as a combination of straight line segments

  • October 16, 2019
  • 5 replies
  • 8894 views

Hello

I would like to convert a given set of data to a segment of straight lines, rather than a perfect curve. For example, in  the attached picture, I would like to convert the data for the sine curve into a set of straight line. Two examples are illustrated in the attachment. One is an approximation connecting the peaks and zeros and the other is more refined approximation. If I use the regression (least square method) on the sine curve, I get a horizontal line.

Question: how to convert the given sine curve data into a set of lines and make them more refined, i.e., with the help of some refining variable. 

5 replies

23-Emerald I
October 16, 2019

If you have the data as matched pairs X and Y, the command is

 

fn(x) := linterp(X,Y,x)

16-Pearl
October 16, 2019

I'd do it like this.  change spacing variable to control the fit.

 

2019-10-16_7-40-42.png

16-Pearl
October 16, 2019

Or for some more sophisticated approaches see this thread

 

https://community.ptc.com/t5/PTC-Mathcad/Calculating-slope-in-dataset/td-p/498334/page/2

adar1-VisitorAuthor
1-Visitor
October 30, 2019

Thanks for the thread. Yes, that is what I was looking for. 

 

23-Emerald IV
October 16, 2019

What exactly do you need?

Do you just want the graph to be more or less 'refined', like this:

clipboard_image_0.png

Or do you want the line properties for each of the line segments that make up your curve approximation, like this:

clipboard_image_1.png

Above is an example with 4 line segments. With 6 line segements you get:

clipboard_image_2.png

 

Success!
Luc

adar1-VisitorAuthor
1-Visitor
October 29, 2019

Thanks. I am looking for regression analysis for a given data in form of a set of lines with properties of each segment. The sine curve was just an example. Here the 'sine' curve should be treated as unknown.  I have tried to explain it better in the attached worksheet. Please see attached. 

23-Emerald I
October 29, 2019

The challenge with fitting a set of straight lines to a non-linear data set lies in determining where the "break points" are.  If you can divide the data into groups that define each line segment (command would be "submatrix"), then either "line," or "intercept," and "slope" will give you the least squares linear fit.  But automating the choice of where to split up the data set will be challenging.

21-Topaz II
October 29, 2019

Hi,

the simplest way possible:

the simplest way possible.jpg

the simplest way possible 1.jpg