LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/5/2009) - General Polynomial Fit VI

I am back from one trip, and have a couple of days before the next, so time for a few more installments.  I am in a curve fitting mood, so a trifecta of fitting this week.  To get warmed up, today it is "General Polynomial Fit.vi".  This VI uses the linear least squares method to fit a polynomial to a set of data points.  It is a special case of the general least squares VI (tomorrow's VIOTD) in that it calculates the design matrix for you.

 

A few notes about the choices you face using this VI.  The first is the weight, unless I have outliers or specifically know the uncertainties in the y values I usually leave this one empty to weight all points equally.  The second choice is the algorithm.  Singular Value Decomposition is the method of choice for least squares problems.  It may not be the fastest, but it is very robust.   The two Givens methods are prone to roundoff and overflow and therefore I believe that Householder is a better choice than either of those.  Cholesky is a reasonable choice and I have never had a chance to try LU decomposition.  Overall, I would suggest that SVD be used essentially all the time.

 

Now to fit something.  I am bored with the usual methods of generating fake data so in this example you can click on the graph to place data points along the cable of a suspension bridge.  When you have chosen at least three points click fit and you will see the parabolic shape of the cable.

Message 1 of 4
(3,191 Views)

A cable which suspends only its own weight follows a catenary curve not a parabola, although they look similar.  I am not sure how much the loading of a suspension bridge changes the shape of the curve.  The catenary cure is a hyperbolic cosine.  Search Wikipedia for "catenary."

 

Lynn 

0 Kudos
Message 2 of 4
(3,177 Views)

A suspension bridge cable is loaded primarily by the bridge deck via the vertical cables (visible in the picture) which are evenly spaced horizontally.  With even loading per horizontal distance, the solution is a parabola.  Under its own weight, the loading is even per unit length of the cable (ds instead of dx).  In this case you are solving a version of the brachistochrone problem and get the catenary solution.

 

I haven't tried, but if you try fitting the cable shape to a catenary I imagine you'll see some differences at the edges since the catenary has more curvature than the parabola. 

 

Thanks for jogging the old memory.   When I see a suspension bridge I just think parabola, I hadn't thought about why that is for a while. 

Message Edited by Darin.K on 10-05-2009 09:56 AM
0 Kudos
Message 3 of 4
(3,172 Views)
I used to use this a lot, but got burned too many times by outliers.  Least squares fitting is very sensitive to outliers and typically gives you a poor result when they exist.  The problem is that least squares fitting weights a point by the square of its distance from the fit line (usually the Y distance, not the perpendicular distance).  One outlier can easily skew the entire curve.  More robust fitting usually uses a distribution with a more peaked center and longer tails (or other algorithms, such as tossing outliers after the original fit).  Examples of this are the double exponential and Lorentzian distributions, which respectively use the absolute value of the distance and the log of the absolute value of the distance for weighting the points.  Unfortunately, there is no general case closed form solution for these distributions, so an iterative solution using a general purpose "find minimum" algorithm must be used.  I tend to use the Lorentzian distribution with the downhill simplex minimizer.  I generate a starting solution using the least square solution.  For more details on these methods, check out the online editions of Numerical Recipes in C.
Message 4 of 4
(3,134 Views)