Skip to main content
Engineering LibreTexts

7.3: Implement the Program

  • Page ID
    54269
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Based on the algorithm, the following program can be created.

    program period
    ! Program to calculate the period of a pendulum
    
    ! declare variables
    !     real constants -> gravity, pi
    !     reals -> angle, length, alpha
    implicit none
    real :: angle, length, pperiod, alpha
    real, parameter :: gravity=980.0, pi=3.14159
    
    ! display initial header
        write (*,*) "Pendulum Period Calculation Program"
        write (*,*)
    
    ! prompt for and read the length and angle values
        write (*,*) "Enter Length and Angle values:"
        read (*,*) length, angle
    
    ! convert degrees to radians
        alpha = angle * pi / 180.0
    
    ! calculate the period
        pperiod = 2.0 * pi * sqrt(length/gravity) * &
            ( 1.0 + 1.0/4.0 * sin(alpha/2.0)**2 )
    
    ! display the results
        write (*,*) "The period is:", pperiod
    
    end program period
    

    The indentation is not required, but helps make the program easier to read. Note that the “2”, “1”, and “4” in the algorithm are entered as 2.0, 1.0, and 4.0 to ensure consistent data typing (i.e., all reals). When 1 divided by 4 is entered as “1/4” instead of “1.0/4.0” the result will be 0 because that would be integer division.


    This page titled 7.3: Implement the Program is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?