Re: best linear fit to a curve



"John D'Errico" <woodchips@xxxxxxxxxxxxxxxx> wrote in
message <fsa676$2vl$1@xxxxxxxxxxxxxxxxxx>...
"Jonathan Schell" <jschell@xxxxxxxxxxxxxxxxxxxx> wrote in
message
<fs9kd5$4r0$1@xxxxxxxxxxxxxxxxxx>...
"John D'Errico" <woodchips@xxxxxxxxxxxxxxxx> wrote in
message <fs9jit$ra8$1@xxxxxxxxxxxxxxxxxx>...
"Jonathan Schell" <jschell@xxxxxxxxxxxxxxxxxxxx> wrote in
message
<fs9ih7$ih7$1@xxxxxxxxxxxxxxxxxx>...
I have a curve defined by a series of points in a
2-d array
and I need to get the best linear approximation for it.
More specifically, I need the 8 points that will be
the best
linear fit for the curve. I don't know the correct
terminology so I don't know what to search for to
figure out
how to do this. Right now I'm just guessing at
where to put
the points based on looking at the graph and
adjusting it
until it looks ok, but I'd like the computer to
figure this
out for me. :)

Please be more specific.

Do you have a function y = f(x), with a single
independent variable. Now you want to find
that subset of 8 of your points which yields
the best linear fit?

Or have I misunderstood the problem?

John

No, I don't have a function. I have a set of points,
anywhere from 2 to 3000, in an array. It's just a sequence
of x,y coordinates. I need the 7 best fitting lines (8
points) that will most closely resemble that curve when
graphed.

Ok. So you wish to find a piecewise linear
approximation to your curve. I'd never have
guessed this from your first post.

The problem is its not hard if you are willing
to define the breakpoints in advance. Then
its really just a least squares linear spline.
You can find this in the splines toolbox.

If you are not willing to fix the break points
in advance, then its a free knot spline problem.
Estimation of the knot positions is quite a
bit more difficult, although there are several
algorithms out there that try to do so.

Simplest is just to use the optimization
toolbox to find the breaks, though even
that has issues. Other methods (MARS) use
stepwise regression methods to insert knots
until the desired number have been placed.

John

Piecewise linear approximation sounds right. I want to
break my curve into segments and get the closest linear
approximation to the curve, but I want to be able to
calculate where to make the break rather than set them
manually, which is what I'm doing now. I'm assuming that
this is what you mean when you say "break points".

I can write a program that will try all the possible spots
along the curve and test each time to see which spots create
the best fit for all 7 segments, but I wanted to know if
Matlab already had that functionality, because it would be
easier to script it in Matlab than to write it in C or Fortran.
.



Relevant Pages

  • Re: Linearly spaced datapoints along 3D spline
    ... spaced data points along a spline, ... Then over x = 0 to 2*pi, this describes a single sine curve ... spacing would be linear from the perspective of x. ...
    (comp.soft-sys.matlab)
  • Re: Linearly spaced datapoints along 3D spline
    ... spaced data points along a spline, ... Then over x = 0 to 2*pi, this describes a single sine curve ... spacing would be linear from the perspective of x. ...
    (comp.soft-sys.matlab)
  • Re: exponential fitting?
    ... a spline is a better choice. ... squares spline on your data. ... chosen end conditions) fit your curve quite well. ... piecewise linear function. ...
    (comp.soft-sys.matlab)
  • Re: Confusion about splitting classes to allow sharing of resources
    ... > selecting algorithms is a good job for patterns like Strategy. ... Spline classes, such as LinearSpline and CubicSpline, based on the same ... The higher-level class Curve should be able to select ... >> interpolation data gets regenerated. ...
    (comp.object)
  • Re: Revolve 3D curve?
    ... Hardly surprising, for the "2 sketch" sweep, that it conforms exactly. ... spline, being the starting profile for the sweep, forms a boundary of the ... I would expect that divergence would not be ... > the 3D curve. ...
    (comp.cad.solidworks)