Elegant proofs 3

At The Math Less Travelled it says:

“Did you know that the ratio between the side of any triangle and the sine of the opposite angle is equal to the diameter of the triangle’s circumcircle? I didn’t! I just learned it today when researching the law of sines. All that time spent on the law of sines in high school, and no one ever bothered to tell me that in any triangle, not only are all the ratios between side lengths and sines of opposite angles equal to each other, they are also equal to something else interesting — namely, the diameter of the circumcircle!

Among other things, this means in particular that if you inscribe any angle in a circle with diameter one, the length of the chord it subtends is equal to the sine of the angle:”

Follow the link above for a very neat wordless proof of this proposition, and see below for my own, possibly even neater, proof, using exactly the same number of words:

sinproof

Posted in Maths, Newton | Tagged , , | Leave a comment

Another old bridge, and some newer ones

A further collection of notable bridges from Southern Germany and Austria.

Würzburg’s Old Main Bridge (Alte Mainbrücke) was built 1473–1543 to replace the destroyed Romanesque bridge from 1133. It was adorned from 1730 on in two phases with well-known statues of saints and famous persons.

Wurzburg Old Bridge and the Fortress Marienberg

Wurzburg Old Bridge and the Fortress Marienberg

 

Wurzburg Old Bridge and the city from the fortress

Wurzburg Old Bridge and the city from the fortress

 

Statues on the Wurzburg Old Bridge

Statues on the Wurzburg Old Bridge

 The concrete arch bridge upstream of the old bridge at Wurzburg is also an elegant structure, but one about which I have not been able to find any details.

A newer arch bridge at Wurzburg

A newer arch bridge at Wurzburg

 

The Ludwigsbrucke is immediately oustside the Deutsche Museum in Munich, which includes, amongst many other exhibits, an interesting bridge exhibition.  The Ludwigsbrucke was constructed in 1936 with a span of 43 m, and was an early example of the use of precasting, with the arch soffit being formed from precast concrete, which was used as permanent form-work for the main concrete structure.

Ludwigsbrucke, Munich

Ludwigsbrucke, Munich

 

The nearby Luitpoldbrucke is similar in appearance, but is larger and older.  Built in 1901 with 63 m span.

Luitpoldbrucke, Munich

Luitpoldbrucke, Munich

 Of the bridges crossing the Salzach River at Salzburg it is the Mozart Footbridge (2nd from top) which is the most famous (having been filmed together with young Trapps practicing their scales in the Sound of Music), but to my mind the recent concrete footbridge is the more attractive.

Five bridges crossing the Salzach River at Salzburg

Bridges crossing the Salzach River at Salzburg

Footbridge over the Salzach River, Salzburg

Footbridge over the Salzach River, Salzburg

Posted in Arch structures, Historic Bridges, Newton | Tagged , , , | Leave a comment

Trigonometric Functions in VBA – Update

In this post from February a set of VBA trigonometric functions were presented, using the derivations given on the Microsoft Developer Network site:

Derived Math Functions

Unfortunately two of the functions were wrong; the correct versions are shown below:

Inverse Secant Arcsec(X) = Atn(1 / Sqr(X * X – 1)) + Sgn((X) -1) * (2 * Atn(1))
Inverse Cosecant Arccosec(X) = Atn(1 / Sqr(X * X – 1)) + (Sgn(X) – 1) * (2 * Atn(1))

I have corrected the spreadsheet, which can be downloaded from: VBA Trig Functions

Does anyone know how I can notify Microsoft of the error?

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

The Moon Smiles on Brisbane Water

Astronomy Picture of the Day for Friday Dec 5th:

“Explanation: At sunset, Monday’s western sky showed off stunning colors and dramatic clouds reflected in Brisbane Water on the Central Coast of New South Wales, Australia. It also featured the remarkable conjunction of the crescent Moon, Venus, and Jupiter forming a twilight smiley face. While the gathering of the two bright planets and Moon awed skygazers around planet Earth, astronomer Mike Salway reports taking special pains to record this gorgeous view, braving mosquitos and rain squalls along a soggy shore. His southern hemisphere perspective finds brilliant Venus at the highest point in the celestial grouping. For now, a bright pairing of Venus and Jupiter continues to dominate the western horizon after sunset but the Moon has moved on and tonight is near its first quarter phase. ”

And something completely different.

Posted in Newton | Tagged , | Leave a comment

Linking Excel to Fortran – 2

In this post the procedures described for C++ here will be replicated for Fortran:

The spreadsheet, fortran source code, and compiled dll described in this code may be downloaded from Cubic.zip

As always, it is better to use the downloaded code, rather than copying from the post, because the WordPress software changes quotes (“”) and several other characters, so that code copied and pasted from the post will often not run without editing.

This post describes:

  • Transferring arrays between VBA and Fortran.
  • Writing and compiling a simple Fortran function to solve quadratic equations, and linking to it from Excel.
  • Compiling a Fortran function to solve cubic equations, and linking from Excel. 
  • The Fortran code for the quadratic function (QUADA) is shown below:


    F_stdcall FUNCTION QUADA(qdat, ResA, NumRows)
    IMPLICIT NONE

    INTEGER, intent(in) :: NumRows
    REAL(2), intent(in) :: qdat(NumRows, 3)
    REAL(2), intent(out) :: ResA(NumRows,2)

    REAL(2) :: QUADA
    REAL(2) :: P, DIS

    INTEGER I

    DO I=1, NumRows

    IF (qdat(I,1).NE.0.D+0) THEN

    ! quadratic problem
    P=5.D-1*qdat(I,2)/qdat(I,1)
    DIS=P**2-qdat(I,3)/qdat(I,1)
    IF (DIS.GE.0.D+0) THEN
    ! two real solutions!
    ResA(I,1)=-P-SQRT(DIS)
    Resa(I,2)=-P+SQRT(DIS)
    QUADA=2
    ELSE
    ! no real solution!
    QUADA=0
    END IF

    ELSE IF (qdat(I,2).NE.0.D+0) THEN

    ! linear equation
    ResA(I,1)=-qdat(I,3)/qdat(I,2)
    QUADA=1

    ELSE
    ! no equation
    QUADA=0
    END IF
    END DO

    RETURN
    END FUNCTION QUADA

    Note that:

    • The function is preceded with “F_stdcall”
    • The function parameters: qdat, ResA, and NumRows are declared as either intent(in) or intent(out); intent(inout) is also allowed.
    • The arrays qdat and ResA are dynamic, and will be sized at run time to the size specified in NumRows
    • Paramaters that are specified as double in VBA are REAL(2) in Fortran
    • Parameters specified as Long in VBA are Integers in Fortran
    • It is essential to ensure that both the data types and the sizes of arrays in the VBA and Fortran routines match.

    The fortran routine is compiled as a dll as before, and may then be called from a VBA routine.  The dll has been named cubic.dll, since it contains both the quadratic and cubic functions:


    Declare Function QUADA Lib "D:\Users\...\Cubic\Release\Win32\Cubic.dll" (qdat As Double, ResA As Double, NumRows As Long) As Double

    Function FQuada(QuadData As Variant) As Variant
    Dim xa() As Double
    Dim A As Double, b As Double, c As Double
    Dim ResA() As Double, NumRows As Long
    Dim Retn As Double, i As Long, j As Long
    On Error Resume Next

    QuadData = QuadData.Value2
    NumRows = UBound(QuadData) – LBound(QuadData) + 1

    ReDim xa(1 To NumRows, 1 To 3)
    ReDim ResA(1 To NumRows, 1 To 2)
    For i = 1 To NumRows
    For j = 1 To 3
    xa(i, j) = QuadData(i, j)
    Next j
    Next i
    Retn = QUADA(xa(1, 1), ResA(1, 1), NumRows)

    FQuada = ResA

    End Function

    As for C++ dlls, array parameters are passed by reference by entering the first member of the array. Unlike C++, in Fortran the array members are named in the same way as VBA; i.e. ArrayName(Row No, Column No).

    A screen shot showing the output of the quadratic function is shown below:

    Output from QuadA

    Output from QuadA

    Fortran code for two Cubic functions, and the resulting dll, are included in the download files.  The code to call these functions from VBA is shown below:
    Declare Function CUBIC Lib “D:\Users\…\Cubic\Release\Win32\Cubic.dll” (cdat As Double, ResA As Double) As Double
    Declare Function CUBICA Lib “D:\Users\..,\Cubic\Release\Win32\Cubic.dll” (cdat As Double, ResA As Double, NumRows As Long) As Double

    Function FCUBIC(P As Variant) As Variant
    Dim P1(1 To 4) As Double, Res(1 To 1, 1 To 3) As Double
    Dim cval As Double, i As Long

    P = P.Value

    For i = 1 To 4
    P1(i) = P(1, i)
    Next i

    cval = CUBIC(P1(1), Res(1, 1))

    FCUBIC = Res

    End Function

    Function FCubica(CubicData As Variant) As Variant
    Dim xa(1 To 4) As Double
    Dim ResA1() As Double, ResA(1 To 1, 1 To 3) As Double, NumRows As Long
    Dim Retn As Double, i As Long, j As Long
    On Error Resume Next

    CubicData = CubicData.Value2
    NumRows = UBound(CubicData) – LBound(CubicData) + 1

    ReDim ResA1(1 To NumRows, 1 To 3)
    For i = 1 To NumRows
    For j = 1 To 4
    xa(j) = CubicData(i, j)
    Next j
    Retn = CUBIC(xa(1), ResA(1, 1))
    For j = 1 To 3
    ResA1(i, j) = ResA(1, j)
    Next j
    Next i

    FCubica = ResA1

    End Function

    Function FCubica2(CubicData As Variant) As Variant
    Dim xa() As Double
    Dim ResA() As Double, NumRows As Long
    Dim Retn As Long, i As Long, j As Long
    On Error Resume Next

    CubicData = CubicData.Value2
    NumRows = UBound(CubicData) – LBound(CubicData) + 1
    ReDim xa(1 To NumRows, 1 To 4)
    ReDim ResA(1 To NumRows, 1 To 3)
    For i = 1 To NumRows
    For j = 1 To 4
    xa(i, j) = CubicData(i, j)
    Next j
    Next i
    Retn = CUBICA(xa(1, 1), ResA(1, 1), NumRows)

    FCubica2 = ResA

    End Function

    The code includes one function that operates on one equation at a time, and two alternative array functions that provide much better performance by avoiding the transfer of data between the spreadsheet and VBA. For comparison VBA cubic functions are also included in the download file.

    Screenshot of cubic function output and relative performance results:

    cubic

    Posted in Excel, Fortran, Link to dll, Maths, UDFs, Uncategorized, VBA | Tagged , , , , , | 23 Comments