Maximum distance between two points

I have just written a short User Defined Function (UDF) to find the maximum distance between any two points from a list of coordinates, and since it may be useful to others, I will post it here.  Here is the code:


Function MaxDist(XRange As Variant, YRange As Variant) As Variant
    Dim i As Long, j As Long, MDRes(1 To 1, 1 To 4) As Double, Dsq As Double, MaxD As Double
    Dim Maxi As Long, Maxj As Long, NumRows As Long, STime As Single

    If TypeName(XRange) = "Range" Then XRange = XRange.Value2
    If TypeName(YRange) = "Range" Then YRange = YRange.Value2

    STime = Timer
    NumRows = UBound(XRange)

    If UBound(YRange) <> NumRows Then
        MaxDist = "X and Y ranges must be the same length"
    End If

    If NumRows < 2 Then
        MaxDist = "Must be at least 2 pairs of coordinates!"
    End If

    For i = 1 To NumRows - 1
        For j = i + 1 To NumRows
            Dsq = (XRange(i, 1) - XRange(j, 1)) ^ 2 + (YRange(i, 1) - YRange(j, 1)) ^ 2
            If Dsq > MaxD Then
                MaxD = Dsq
                Maxi = i
                Maxj = j
            End If
        Next j
    Next i
    MDRes(1, 1) = MaxD ^ 0.5
    MDRes(1, 2) = Maxi
    MDRes(1, 3) = Maxj
    MDRes(1, 4) = Timer - STime

    MaxDist = MDRes
End Function

The function returns the maximum distance between any two points and the row numbers of the two points.  To return all three values enter as an array function:

  • Enter the function as a normal function.
  • Select the cell with the function and the adjacent two cells
  • Press F2 (Edit)
  • Press Ctrl-Shift-Enter

This function and a variety of other coordinate geometry related functions are included on the spreadsheet IP2.xls, with full open source code.  More details of IP2 here.

MaxDist in action

Posted in Coordinate Geometry, Excel, Maths, Newton, UDFs, VBA | Tagged , , , , | 1 Comment

New Excel Engineering Blog

I just found Excel Unusual, which has been going since September this year.  Here’s what the Author says:

“Finding engineering work quite un-challenging lately I decided to start this blog in which to share cool ways of solving engineering problems or just interesting modeling of natural phenomena in MS Excel 2003. I use mainly cell formulas with minimum of VBA in order to take advantage of the ease of “programming” and the native speed of the Excel spreadsheet.”



He has some amazing stuff on there, including this Excel generated simulation of a roller coaster:

Have a look!

Posted in Animation, Excel, Newton | Tagged , , , , | 13 Comments

RSS Feeds and Comments

I haven’t been using RSS feeds myself up to now, and I assumed they were just available for those who did, but it seems you have to activate them, so I have done that and you can now click on the buttons on the right which connect to:

https://newtonexcelbach.wordpress.com/feed/

https://newtonexcelbach.wordpress.com/comments/feed/

Also I’d encourage readers to post comments with questions, suggestions, and additional information.  It’s the comments as much as the content that makes sites like Daily Dose of Excel such a valuable resource, and as the traffic here increases I hope we can develop an equally worthwhile dialog.

Look forward to hearing from you 🙂

Posted in Computing - general | Tagged , | 4 Comments

Tanh-Sinh Quadrature Update 2

I have copied the latest version of Graeme Dennes’ Tanh-Sinh Quadrature spreadsheet to my download site:  Click here to download Tanh-Sinh.zip

As before, the download includes full open-source code, and detailed notes by Graeme.

In the new version the Gauss-Kronrod function has been modified to give similar precision to the Tanh-Sinh function.  The result is that on a like for like basis the Tanh-Sinh function now averages 40 times faster than the Gauss-Kronrod function, and in one case it is about 750 times faster!

The screen-shots below show the recalc times and cumulative errors for integration of 55 different functions, using the three different integration methods.  I recommend this spreadsheet to anyone looking for an efficient high precision numerical integration method.

Tanh-Sinh Function; click to view full size

Gauss-Kronrod Function

Romberg Function

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

The structural analysis of domes: From Pantheon until Reichstag

An interesting paper with technical details of several historical domed structures, available for free download, from Dokuz Eylul University, Izmir, Turkey:
The structural analysis of domes

Posted in Arch structures, Newton | Tagged | 1 Comment