On this page
Worked examples
All computer programs, regardless of purpose, serve as a sequence of instructions that execute a particular function. That function may be to control a character on the screen in a video game or it could be to calculate the appropriate distance and direction a neutron will travel after an elastic scatter with a moderator. In either case, the computer performs a set of well-defined steps in a logical format to achieve a predictable result. These steps are known as an algorithm . An algorithm is a method to solve a problem. A function is a block of code in the program that performs a specific task. Programs are made of multiple algorithms that execute functions to perform achieve a desired result. To create a computer program, the programmer uses source code statements to write the functions. These statements are readable by the programmer but, except in rare instances, are not understood by the computer until the program is compiled into an executable code. The source code consists of specific instructions that execute the logical flow of arguments using commands such as WHILE, DO, PRINT, IF, THEN etc. Programming languages have syntax and commands specific to that language. Much like spoken languages, computer languages have specific vocabulary and rules. Also, as with verbal a language, a knowledge of one code facilitates the learning of another one. The programmer can often translate their knowledge of C++ to FORTRAN, Julia or Python or some other application. (Lindeburg; 2021)
The majority of processes performed in nuclear engineering programs are mathematical calculations. Depending on the programming language, to begin the algorithm, the programmer should specify the variables and constants used in the program. The specification of variables is known as declaration . Declarations describe the variable type (INTEGER, REAL, BOOLEAN, LONG etc.) and give it an assignment which reserves computer memory space to hold the information. The declaration of variable types is required in programs like C++ and Java. In some programs, there are pre-defined constants (such as pi) that are available for use. In Julia, the user defines variables and constants that are not already in the program in the same manner as in a compiled program, but do not have to specify the type or provide an assignment. Variables in Julia are declared by writing their name. Julia does not require the user to define a datatype of the variable. Initializing variables is performed at the time of declaring variables. (GeeksforGeeks; 2023)
Logical Flowcharts
Logical flowcharts are useful to visually display how the computer steps through a particular algorithm. Table 2.1 lists some of the various symbols used to create a flowchart.
Table 2.1. List of Key Logical Flowchart Symbols and their Meanings
| Symbol | Purpose | Description | Symbol | Purpose | Description |
|---|---|---|---|---|---|
![]() | Flow line | Indicates the flow of logic by connecting symbols | ![]() | Decision | Operation with two alternatives, true and false. |
![]() | Terminal (Stop/ Start) | Represent start and end of flowchart | ![]() | On-page Connector | Join different flow line |
![]() | Input/ Output | Input and output operation | ![]() | Off-page Connector | Connect flowchart portion on different page |
![]() | Processing | Arithmetic operations and data-manipulations | ![]() | Predefined Process/ Function | Group of statements performing one task |
Figure 2.2 is a representation of a logical flowchart used for a simple workout plan. In the plan, the program first evaluates the time (morning or afternoon). Based on that result, it transitions to the day of the week and then the workout for that period. The program terminates once a workout has been assigned.

Example 2.1
Using the symbols presented in Table 2.1, write a flowchart that shows the logic of an algorithm that rounds numbers to three significant figures if possible.
Solution:

Note that if a number is > 999 and has < 3 SFs, such as 1000, it is not possible to round to 3 SFs. However, a number like 900 can have 3 SFs with the addition of a decimal (900.). Similarly, 0.0045 has only two SFs while 0.00450 has three.
Computer Language Levels
As indicated earlier, there are various types of languages used in programming. In general, there are two types of languages — low level and high level. Low level languages are machine and assembly language. Machine language is understood by the computer’s central processing unit and is not normally used for coding alone. Assembly language code is translated into machine language using an assembler. Assembly language code is usually very efficient but rather complex to understand and not normally used for large applications. Table 2.2 is a summary of high and low level codes.
Table 2.2. Summary of High and Low Level Computer Codes
| Code Level | Description | Examples |
|---|---|---|
| Low | Codes that work directly with the machine’s CPU | Numerical Machine Code, X86 |
| High | Codes that use commands or functions and are either interpreted or compiled into machine code | Julia, Python, Java, C++, FORTRAN |
High level languages are more intuitive to use because they use commands that are similar to written language. The programmer uses specific words and characters, or syntax, specific to the programming language to generate the functions. High level languages can be either compiled or interpreted. Interpreted codes, like Julia and Python, use a computer code to run the user’s commands. This, interpreter, is the interface between the computer’s machine language and the programming language. Interpreted codes can’t run on a computer without the interpreter installed. Compiled languages, on the other hand, are programmed in the programming language and then a compiler creates an executable for the program to work on the machine in the machine language. The machine language is specific to the operating system, DOS, Linux, Apple-OS etc. Once compiled, the source code can no longer be easily viewed or modified. However, the compiled executable is now usable on any machine with the correct operating system installed. The major disadvantage to a compiled program is that it will often take more time to compile and debug than an interpreted program and every modification to the program will require it to be compiled again. It is for these reasons that many engineering students will use an interpreted program to write simple scripts to solve problems. Because of the popularity of interpreted programs, there are now some tools developed to serve as pseudo-compilers to allow portability for scripts.
Function Syntax for Operations
There are several excellent references for compiled and interpreted programs that detail all of the various rules and commands for syntax and even more online resources like https://julialang.org. Whatever the programming language, there are some essential commands necessary to complete a working script for engineering problems. The compiled or interpreted program must be able to interface with the user (input/output), it must be able to conduct basic mathematical operations, store and retrieve information (variables and constants) and it must be capable of conducting loops and conditional statements. Within these constructs, the programmer can write functions that will solve problems, export data, evaluate and plot results.
Table 2.3. Common Julia Mathematical Operations and Functions (JuliaLang.org; 2023)
| Expression | Name | Description |
|---|---|---|
+x | unary plus | the identity operation |
– x | unary minus | maps values to their additive inverses |
x + y | binary plus | performs addition |
x – y | binary minus | performs subtraction |
x * y | times | performs multiplication |
x / y | divide | performs division |
x ÷ y | integer divide | x / y, truncated to an integer |
x \ y | inverse divide | equivalent to y / x |
x ^ y | power | raises x to the y power |
x % y | remainder | equivalent to rem(x,y) |
== | equality | comparison exactly equal to |
!= , \neq | inequality | comparison not equal to |
< | less than | comparison less than |
<=, \leq | less than or equal to | comparison less than or equal to |
> | greater than | comparison greater than |
>=, \geq | greater than or equal to | comparison greater than or equal to |
sqrt(x), \surdx | square root | square root of x |
abs(x) | absolute value | a positive value magnitude of x |
exp(x) | exponential | natural exponential function at x |
log(x) | natural log | natural logarithm of x |
mod(x,y) | modulus | remainder of modulo function |
cos(x) | cosine | cosine of x |
acos(x) | arc cosine | inverse cosine of x |
sin(x) | sine | sine of x |
asin(x) | arc sine | inverse sine of x |
tan(x) | tangent | tangent of x |
atan(x) | arc tangent | inverse tangent of x |
High-level programs, especially interpreted codes, have many built-in functions available to the user that facilitate solving problems. An excellent illustration was presented in Example 1.1 of this text. In Example 1.1, we used the ODEProblem solver from the DifferentialEquations package within Julia to solve the series of first-order linear ordinary differential equations. The ODEProblem is one of the 21 integrated ODE solvers in Julia’s DifferentialEquations package that uses the Runge-Kutta integration algorithm. (Rackauckas and Nie; 2017) We could have written our own function to solve the ODE where we read the equations into a matrix and solved using standard mathematical techniques. This would have negated the advantage of using Julia over another programming language.
Many programming languages use similar functions and syntax. Julia uses several mathematical operators and commands similar to C++ and Python. Most engineering applications do not require the use of many of the high-level features of languages that are necessary for graphics, Windows® interfacing, and similar operations. Engineering programs are often optimized for speed and flexibility and are utilitarian in design with little concern for graphics, colors, sounds etc. Table 2.3 is a consolidated list of many of the operations and functions used in Julia. (JuliaLang.org; 2023)
References
Full bibliography- GeeksforGeeks (2023). Variables in julia. URL: https://www.geeksforgeeks.org/julia/variables-in-julia/
- JuliaLang.org (2023). Julia language documentation. URL: https://docs.julialang.org
- Lindeburg, M. R. (2021). FE Other Disciplines Review Manual: Rapid Preparation for the Other Disciplines Fundamentals of Engineering Exam, PPI. https://books.google.com/books?q=intitle:%22FE+Other+Disciplines+Review+Manual%22+inauthor:Lindeburg
- Rackauckas, C. and Nie, Q. (2017). Differentialequations.jl–a performant and feature-rich ecosystem for solving differential equations in julia, Journal of Open Research Software 5(1). https://doi.org/10.5334/jors.151








