Curve fitting as a combination of straight line segments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If you have the data as matched pairs X and Y, the command is
fn(x) := linterp(X,Y,x)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I'd do it like this. change spacing variable to control the fit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks for the thread. Yes, that is what I was looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here is your data, with four line fits (done in EXCEL). But where you set the ends of the fits makes a huge difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
thanks. this might work. but I was looking for a solution in Mathcad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Note sure what you intend to do with the regression lines you are looking for.
Maybe simple linear interpolation is all you need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
the simplest way possible:
![](/skins/images/695EE5AD3E567050FEDD72575855ED93/ptc_skin/images/icon_anonymous_message.png)