Skip to main content
Engineering LibreTexts

7.2: Create the Algorithm

  • Page ID
    54268
  • \( \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}}\)

    The algorithm is the name for the ordered sequence of steps involved in solving the problem. That sounds good, but it is a fancy way of saying that an algorithm is just a step-by-step procedure to solve a problem. Once the program is understood, the steps can be developed to solve that specific problem. There can be multiple correct solutions to a given problem.

    The process for creating an algorithm can be different for different people. In general, some time should be devoted to thinking about a possible solution. This may involve working on some possible solution on a scratch piece of paper. Once a possible solution is selected, that solution can be developed into an algorithm. The algorithm can be written down, reviewed, and refined. This algorithm is the outline of the program.

    For this problem, the variables and constants must be declared, the applicable headers and prompts displayed, and the values for \(L\) and \(\alpha\) read from the user. The degree entered by the user should be converted to radians1, which is required by the sin function. The formula to convert degrees to radians is as follows:

    \[ \text{radians} = \text{degrees} \cdot \dfrac{\pi}{180} \nonumber \]

    Then the period can be calculated based on the provided formula and the results displayed. Formalizing this, the following steps can be developed and written down as follows:

    ! declare variables
    !     real constants -> gravity, pi
    !     reals -> angle, length, alpha
    ! display initial header
    ! prompt for and read the length and angle values
    ! convert degrees to radians
    ! calculate the period
    ! display the results
    

    While this is a fairly straightforward algorithm, more complex problems would require more extensive algorithms. Examples in later chapters will include more complex programs. For convenience, the steps are written as program comments. This will allow the addition of the code to the basic algorithm.


    1. For more information, refer to: https://en.Wikipedia.org/wiki/Radian

    This page titled 7.2: Create the Algorithm 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?