Evaluating higher order polynomials …

… and a better solution for quadratics.

Having written a better solver for high order polynomials, that raises a few other issues.  The error in the roots found by the RPolyJT was checked by simply substituting each root as the x value in: ax^n + bx^(n-1) + cx^(n-2) + …+e = 0.  The problem is that finding the difference between two similar large numbers significantly reduces the precision of the result.  A much better approach is known as the Horner Scheme, which uses Synthetic Division to arrive at the value of the polynomial without subtraction of the values raised to high powers.

This method has now been added to the Polynomial spreadsheet with the following changes:

  • RPolyJT has been modified to call the new function EvalErrorHC() to evaluate the error in the roots found.
  • EvalErrorHC may also be used as a UDF from the spreadsheet.
  • EvalPolyHC will evaluate any polynomial for a list of values of x (real or complex), which may take any value (i.e. not necessarily estimated roots).

For similar reasons, the standard quadratic formula will not give accurate results when b^2 and 4ac are large and of similar magnitude.  Better accuracy is given by a method included in the Fortran code used as the basis of the RPolyJT function.  The Quadratic function in the Polynomial spreadsheet has now been revised to use this method.

The revised spreadsheet may be downloaded (including full open source code) from:

Polynomial.zip

Results of the new RPolyJT and EvalErrorHC functions are shown in the screen shot below:

Click for full size view

Posted in Excel, Maths, Newton, UDFs, VBA | Tagged , , , , , , | 4 Comments

Solving higher order polynomials

The Quartic spreadsheet presented here previously (most recently here) uses algebraic techniques to provide an “exact” solution to polynomial equations of up to fouth order.  For polynomials of higher order there is no general algebraic solution, and numerical methods are required.  Also under some circumstances the “exact” solution, when evaluated with floating point numbers of limited precision, produces results that are very far from exact.  In these circumstances a well written iterative numerical procedure can give much better results.

One such procedure is the Jenkins-Traub algorithm, which apart from the advantage of one author having an excellent family name, is also said to be both fast and stable.  The Wikipedia article says that it “has been described as practically a standard in black-box polynomial root-finders”.

I have added a VBA user defined function (UDF) implementation of the Jenkins-Traub method to the Quartic spreadsheet, which has been re-named Polynomial.xlsb, and is available for free download, including open-source code. 

Download Polynomial.zip

The VBA code is a translation of Fortran77 code at the NetLib library.  Similar code in Fortran90 format can be found at Alan Miller’s Fortran Software.  Both of these sites are invaluable sources of open source scientific Fortran code.  The chosen routine provides all real and complex solutions to any polynomial with real coefficients.  Fortran routines are also available for polynomials with complex coefficients, but I have not yet translated these.

The screen-shots below show output from the Jenkins-Traub UDF (RPolyJT) for a quartic polynomial, followed by the results from the Quartic UDF for the same input.  Note that the Jenkins-Traub result is close to machine precision, but in this case the Quartic output has errors in the third decimal place.

RPolyJT output for quartic polynomial

Quartic output for the same polynomial

Output from RPolyJT for higher order polynomials is shown in the screenshots below, where the function has been used to solve the equation : 2.x^60 – 1 = 0.  The roots are 60 equally spaced points in the complex plane, with a modulus of 0.5^(1/60).  Note that the input is the range A26:A86; the cells containing zero coefficients could have been left blank, with the same results.  The top and bottom of the input and output results are shown in the two screenshots below:

Top of input and output for 60th order poynomial

Bottom of input and output for 60th order polynomial

Posted in Excel, Maths, Newton, UDFs, VBA | Tagged , , , , , , | 12 Comments

LatPile update

I have just posted an update to the LatpilePY spreadsheet, fixing a bug in the way in which it read the first row of data from input PY curves, which was resulting in the program failing to run if there were two or more PY curves specified.

The revised spreadsheet, including full open source code, can be downloaded from LatpilePY.zip

Posted in Concrete, Excel, Geotechnical Engineering, Newton, UDFs, VBA | Tagged , , , , , , | 2 Comments

Elegant Solutions – completing the square

When I was at school (many years ago), if I recall correctly, we were told of the “completing the square” method of solving quadratic equations, but I never really appreciated the elegance of this method because it was treated as a purely algebraic process, with no reference to the corresponding geometry. To make things worse, we were told that the method would not be included in the all important exams, so we weren’t really listening.

I was reminded of this when reading Ian Stewart’s excellent book “Why Beauty is Truth” where he tells how this method was used by the ancient Babylonians about 3000 years ago, and describes the method in geometric terms, literally completing a square, which makes the result both obvious and elegant.

In brief, the method is as follows:

  1.  Start with an equation of the form: x² + bx = c, where b and c are given values, and we wish to find x.
  2. Draw a square of length x, representing the x² term.
  3. Draw two rectangles of sides x and b/2, representing the bx term
  4. Arrange the three shapes to form a chunky L shape (see spreadsheet below)
  5. “Complete the square” by adding an area of (b/2)² to both sides of the equation
  6. Take the square root of both sides, giving (x + b/2) = √(c + (b/2)²)
  7. Rearrange, giving x = √(c + (b/2)²) – b/2

This is presented in more detail in the spreadsheet below, in a slightly modified form to show the exact equivalence to the “quadratic formula” in its standard form.

The spreadsheet is “live” on sky drive, and should allow viewing in any browser. Click on the “full screen” icon in the bottom right hand corner to view full screen. The spreadsheet can only be edited by approved persons (currently only me), but anyone should be able to download it.

Posted in Excel, Maths, Newton | Tagged , , , , | 1 Comment

2010 in review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Wow.

Crunchy numbers

Featured image

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 130,000 times in 2010. If it were an exhibit at The Louvre Museum, it would take 6 days for that many people to see it.

In 2010, there were 98 new posts, growing the total archive of this blog to 280 posts. There were 266 pictures uploaded, taking up a total of 21mb. That’s about 5 pictures per week.

The busiest day of the year was November 24th with 651 views. The most popular post that day was Frame Analysis with Excel – 7; Shear deflections and support displacements.

Where did they come from?

The top referring sites in 2010 were en.wikipedia.org, eng-tips.com, spreadsheetpage.com, dailydoseofexcel.com, and blogs.msdn.com.

Some visitors came searching, mostly for tessellations, com624, newton’s cradle animation, heidelberg, and newton excel bach.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

Frame Analysis with Excel – 7; Shear deflections and support displacements May 2009
28 comments

2

Cubic Splines July 2009
4 comments

3

Frame Analysis with Excel 1 – Single beam January 2009
12 comments

4

Frame Analysis with Excel – 3, Continuous beam or frame February 2009
10 comments

5

Using Goal Seek on Multiple Cells July 2009
2 comments

Posted in Computing - general | Tagged | Leave a comment