cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Curve fitting as a combination of straight line segments

adar
6-Contributor

Curve fitting as a combination of straight line segments

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. 

15 REPLIES 15
Fred_Kohlhepp
23-Emerald I
(To:adar)

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

 

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

DJF
16-Pearl
16-Pearl
(To:adar)

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

 

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

DJF
16-Pearl
16-Pearl
(To:adar)

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

adar
6-Contributor
(To:DJF)

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

 

LucMeekes
23-Emerald III
(To:adar)

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

adar
6-Contributor
(To:LucMeekes)

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. 

Fred_Kohlhepp
23-Emerald I
(To:adar)

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.

Here is your data, with four line fits (done in EXCEL).  But where you set the ends of the fits makes a huge difference.

Capture.JPG

adar
6-Contributor
(To:Fred_Kohlhepp)

thanks. this might work. but I was looking for a solution in Mathcad. 

adar
6-Contributor
(To:Fred_Kohlhepp)

Thanks. Yes, that is the challenge. Attached is the mathematical process. I was looking for a function that can do it. 

This is useful in simplification of creating a target response spectrum for seismic testing or design basis where 4 or 5 points cover the entire data which is mean of a much larger set of data. 

Fred_Kohlhepp
23-Emerald I
(To:adar)

I looked at your pdf paper, that should be able to be made to work; but I got lost in the notation changes.  If this author wrote a FORTRAN program then Mathcad can certainly handle this problem.  The only issue would be how many line segments to use--the author compares 2, 3, and 4 lines in his paper.  Clearly the best linear line fit would be to connect the dots (linterp), but it will be difficult to automate a different criteria.

adar
6-Contributor
(To:Fred_Kohlhepp)

thanks. 

Werner_E
24-Ruby V
(To:adar)

Note sure what you intend to do with the regression lines you are looking for.

Maybe simple linear interpolation is all you need?

B.png

 

adar
6-Contributor
(To:Werner_E)

thanks. linterp  will not give me a set of four or five straight lines. I have to provide a simple chart that is used as the design basis based on the data which is the mean curve of a large set of curves (response spectra of earthquake records). Building codes provide few points which define the seismic design basis for a site. I am trying to do something similar. see my reply to the other post where I have attached the literatur to achieve it. 

-MFra-
21-Topaz II
(To:adar)

Hi,

the simplest way possible:

the simplest way possible.jpg

the simplest way possible 1.jpg

Top Tags