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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

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
23-Emerald I

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

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

16-Pearl

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

16-Pearl

Or for some more sophisticated approaches see this thread

6-Contributor
(To:DJF)

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

23-Emerald III

What exactly do you need?

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

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

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

Success!
Luc

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.

23-Emerald I

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.

23-Emerald I
(To:Fred_Kohlhepp)

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

6-Contributor
(To:Fred_Kohlhepp)

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

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.

23-Emerald I

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.

6-Contributor
(To:Fred_Kohlhepp)

thanks.

24-Ruby V

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

Maybe simple linear interpolation is all you need?

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.

21-Topaz II