Wichita State University Logo

Math 451: Computational Mathematics

1.5 Elements of Computer Programming


1.5.1 Flowcharts


A flowchart is a graphical representation of an algorithm.

  1. In the first step(shape) of the algorithm we set the value of variable message to 'Hello World'
  2. In the second step we display the value of the message to the MATLAB command window.



Hello World flowchart

1.5.2 Terminal Elements

A terminal flowchart element is represented by an oval or a rectangle with rounded corners. It indicates either the beginning or the end of an algorithm. They usually contain the work start , stop , or end . Terminal flowchart elements may contain more descriptive phrases

  • A beginning terminal element may describe the purpose or task performed by the algorithm.
  • An end terminal element may describe the result or outcome of the algorithm.



Assignment flowchart

1.5.3 Process Elements

A process flowchart element is represented by a rectangle. It indicates an operation that changes the state of algorithm. It may change to value, definition, form or location of data associated with the algorithm.

Assignment flowchart

This flowchart indicates a simple algorithm that assigns the value of 5 to a variable in the workspace of the algorithm labeled x . In the MATLAB programming language we use the assignment operator = to implement the algorithm such as

> x = 5


On a piece of paper create your own flowchart that assigns the value of 3.1415926 to the variable PI

In most programs the value of $\pi$ never changes. We call such a variable a literal . We created a flowchart for assigning the value of $\pi$ rounded to eight digits to the literal PI .

  • name the start element "Initialize Literal PI"
  • use the left arrow to indicate assignment in a process element
  • name the end element "Return Approximation"

1.5.4 Condition Elements


The condition flowchart element determines which of two paths the algorithm may take. The operation of a condition answers a yes/no or true/false question. A decision flowchart element is usually depicted with a rhombus. The path of the algorithm is determined by the value of result.

A simple decision statement in the MATLAB language is an if statement. The keyword is followed by an expression that results in the value false (0) or true (1). The path taken by the algorithm in the flowchart depends on this value. For example, to make sure that the value assigned to variable x is greater than or equal to zero one might implement the algorithm


Decision flowchart

1.5.5 On Page Connector Element

Consider the decision flowchart above. The decision results in two separate flows of execution ; one assigns the value of x to -x , and the other does nothing. Both flows of execution join together after each subflow or subprocess ends. The separate flows of execution do not always join! When they do one uses a flowchart element to indicate this joining of one or more flows of execution.

The one page connector flowchart element joins several paths of execution . It is represented graphically by a small circle. The size of the circle depends on the choice of the author.

Create a flowchart that uses the decision x > MAXIMUM_VALUE and assigns variable x to the value MAXIMUM_VALUE if it has a larger value.

  • create two separate paths of execution using a decision element
  • join the two execution paths with an on page connector element before ending the algorithm



Connector Flowchart Element

1.5.6 Off-Page Connector Element

When one or paths of execution reside on different pages of your document us an off-page connector flowchart element to join them. For example, a long execution path may not fit on a single page of your document. You must join the single execution path from one page to the next with an off-page connector element. Graphically, the off-page connector looks like a home plate -shaped pentagon.



Off Page Connector Flowchart Element

1.5.7 Comment Element

A comment or annotation flowchart element does not label an action or path of execution. Instead it allows the author to include addition information about another flowchart element or execution path.



Decision Flowchart Element

1.5.8 Predefined Process Element

The predefined process flowchart element indicates the name of an algorithm implemented in another flowchart. One uses this flowchart element to indicate that the algorithm uses another algorithm to accomplish a complex task. This simplifies algorithms and reuses existing algorithms to create more complex tasks.

For example we may call builtin MATLAB function sqrt to compute the square root of the descriminant of a quadratic polynomial.



Predefined Process flowchart element

Create the flowchart for a subprocess that uses the builtin MATLAB function reshape to create a $4\times 4$ matrix of random integers between one and forty two.

  • begin and end your subprocess with an on page connector as in the example.
  • use the builtin MATLAB function randi to create your matrix
  • assign the value of the matrix to the variable A

1.5.9 Input/Output Elements

An Input or Output flowchart element indicates that information is retrieved or emitted to a temporary or permanent medium. Input and output processes are genericall referred to as I/O processes. An I/O process may read or write to a file, write to the screen, read text from the keyboard, or emit strings over an internet connection. I/O flowchart elements are depicted using a parallelogram.



Input/Output Process Elements

Creative Commons Logo - White


Your use of this self-initiated mediated course material is subject to our Creative Commons License .


Creative Commons Attribution-NonCommercial-ShareAlike 4.0

Creative Commons Logo - Black
Attribution
You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

Creative Commons Logo - Black
Noncommercial
You may not use the material for commercial purposes.

Creative Commons Logo - Black
Share Alike
You are free to share, copy and redistribute the material in any medium or format. If you adapt, remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.