Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
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.
If you have the data as matched pairs X and Y, the command is
fn(x) := linterp(X,Y,x)
I'd do it like this. change spacing variable to control the fit.
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
Thanks for the thread. Yes, that is what I was looking for.
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
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.
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.
thanks. this might work. but I was looking for a solution in Mathcad.
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.
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.
thanks.
Note sure what you intend to do with the regression lines you are looking for.
Maybe simple linear interpolation is all you need?
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.
Hi,
the simplest way possible: