thinging matlab for computer engineering · computer science and engineering departments often...

15
Proceedings of the International Conference on Industrial Engineering and Operations Management Riyadh, Saudi Arabia, November 26-28, 2019 © IEOM Society International Thinging MATLAB for Computer Engineering Sabah Al-Fedaghi Computer Engineering Department Kuwait University Kuwait [email protected] Abstract MATLAB’s use has grown from academic research into use as a generalized tool for various applications, but the field of computing does not widely use it. Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than choosing it for real work. Some claim that MATLAB knowledge can make learning another language harder for computer science and engineering beginners with no programming knowledge. Some also claim that MATLAB does not provide a mental model of what the code does. Computer scientists and engineers must understand what the code should do and imagine the data structures. In this paper, we propose applying a recently proposed modeling language called a thinging machine (TM) to help teach MATLAB to computer engineers and scientists as an introductory programming language. This paper presents some MATLAB examples in a TM as they are applied in actual lectures. The initial results indicate potential advantages of TM in this context. Keywords MATLAB; diagrammatic modeling; programming; thinging machine 1. Introduction In the 1960s and 1970s, the programming language FORTRAN (“Formula Translation”) was not very user- friendly, and people struggled to write computer code. Therefore, MATLAB originator Cleve Moler aimed to teach students linear algebra and matrix computation packages without teaching them FORTRAN (Computer Hope, 2019). Accordingly, this motivated the introduction of MATLAB (Matrix Laboratory), which was essentially a “wrapper” for FORTRAN (Cohen, 2018). A wrapper is easy-to-use code that calls hard-to-use code. MATLAB implements mathematical formulas in FORTRAN libraries and focuses on applied linear algebra and matrix decompositions. Over time, MATLAB grew into much more than a simple wrapper. According to Cohen (2018), “It retains its two core themes: An accessible language that non-programmers can easily learn and use; and a strong focus on applied mathematics in education, research, and industry.” 1.1 General View of MATLAB Engineers, physicists, and biologists use MATLAB to analyze, model, and visualize data. This field of study, generally called scientific programming, includes analyzing large-scale, multivariate, and multidimensional datasets as well as processing and coordinating sensory information. MATLAB is commercially available and is considered a standard tool in most universities and industries. Free and open-source MATLAB-compatible solutions also exist, including Octave, Scilab, and FreeMat (Dori et al, 2015). MATLAB is also used for teaching data analysis and mathematics (e.g., translating equations into MATLAB and then simulating and visualizing them). Real applications require moving beyond the basics to mastering the MATLAB language and desktop environment (Cohen, 2018). MATLAB is also an important tool in modeling, which is highly instrumental to studying existing unfamiliar systems—the focus of scientific inquiry. Accordingly, Simulink is incorporated within MATLAB to include Stateflow modules with a graphical environment that replaces the textual code-based view. Simulink’s graphical environment can serve to model a system (Dori et al, 2015). 561

Upload: others

Post on 23-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

Thinging MATLAB for Computer Engineering

Sabah Al-Fedaghi

Computer Engineering Department

Kuwait University

Kuwait

[email protected]

Abstract

MATLAB’s use has grown from academic research into use as a generalized tool for various applications,

but the field of computing does not widely use it. Computer science and engineering departments often

choose a language for the lessons it can teach about programming languages, rather than choosing it for

real work. Some claim that MATLAB knowledge can make learning another language harder for

computer science and engineering beginners with no programming knowledge. Some also claim that

MATLAB does not provide a mental model of what the code does. Computer scientists and engineers

must understand what the code should do and imagine the data structures. In this paper, we propose

applying a recently proposed modeling language called a thinging machine (TM) to help teach MATLAB

to computer engineers and scientists as an introductory programming language. This paper presents some

MATLAB examples in a TM as they are applied in actual lectures. The initial results indicate potential

advantages of TM in this context.

Keywords

MATLAB; diagrammatic modeling; programming; thinging machine

1. Introduction

In the 1960s and 1970s, the programming language FORTRAN (“Formula Translation”) was not very user-friendly, and people struggled to write computer code. Therefore, MATLAB originator Cleve Moler aimed to teach students linear algebra and matrix computation packages without teaching them FORTRAN (Computer Hope, 2019). Accordingly, this motivated the introduction of MATLAB (Matrix Laboratory), which was essentially a “wrapper” for FORTRAN (Cohen, 2018). A wrapper is easy-to-use code that calls hard-to-use code. MATLAB implements mathematical formulas in FORTRAN libraries and focuses on applied linear algebra and matrix decompositions. Over time, MATLAB grew into much more than a simple wrapper. According to Cohen (2018), “It retains its two core themes: An accessible language that non-programmers can easily learn and use; and a strong focus on applied mathematics in education, research, and industry.”

1.1 General View of MATLAB

Engineers, physicists, and biologists use MATLAB to analyze, model, and visualize data. This field of study, generally called scientific programming, includes analyzing large-scale, multivariate, and multidimensional datasets as well as processing and coordinating sensory information. MATLAB is commercially available and is considered a standard tool in most universities and industries. Free and open-source MATLAB-compatible solutions also exist, including Octave, Scilab, and FreeMat (Dori et al, 2015). MATLAB is also used for teaching data analysis and mathematics (e.g., translating equations into MATLAB and then simulating and visualizing them). Real applications require moving beyond the basics to mastering the MATLAB language and desktop environment (Cohen, 2018).

MATLAB is also an important tool in modeling, which is highly instrumental to studying existing unfamiliar systems—the focus of scientific inquiry. Accordingly, Simulink is incorporated within MATLAB to include Stateflow modules with a graphical environment that replaces the textual code-based view. Simulink’s graphical environment can serve to model a system (Dori et al, 2015).

561

Page 2: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

MATLAB was originally implemented in FORTRAN according to the method in Wirth’s “Algorithms + Data Structures = Programs.” MATLAB and its toolboxes are primarily written in C++, Java, and M. In MATLAB, the M Power Query Formula Language is used to build queries that combine data from various data sources. Windows can be opened in MATLAB to access Maple, Java, and .NET. Hundreds of books describe MATLAB (McKeeman, 2005).

Nevertheless, MATLAB is not the best tool for teaching structures and classes, function overloading, inheritance, GIU capabilities, and more (Nikonov, 2006). However, it effectively handles complex numbers and unique operations with matrices and has a powerful library of functions, efficient built-in numerical algorithms, and integrated plotting (Nikonov, 2006). According to Downey (2019), “At heart, MATLAB is a glorified calculator.”

Many people in the open-science and open-software movements think MATLAB will inevitably be surpassed (Guest, 2017). Python is another good programming language for scientific programming (Cohen, 2018). Python may supersede MATLAB (Cohen, 2018), however, MATLAB mastery is an advantage in the foreseeable future for those interested in science, engineering, and applied mathematics.

1.2 Teaching Programming to Computer Engineering Students

In our college of engineering, it is decided to teach MATLAB to all engineering students, including computer engineering students. Although MATLAB has grown from an academic research tool into a generalized tool for various applications, it is not widely used in computing departments. Computer science and engineering departments “often choose the language for the lessons it can teach about programming languages, rather than its general use for doing real work” (Brett, 2017). When McKeeman (2005) visited MIT in 2005, he found that “the computer science department is about the only part of MIT that does NOT use MATLAB.” Rath (2017) complained that the syntax and semantics of MATLAB are not documented and do not support one-dimensional arrays. Vincent (2017) claims people can do object-oriented programming in MATLAB, but setting up classes is “verbose and clunky.” Guest (2017) claimed that:

MATLAB is insufficient to provide a transferable programming skillset. It does not push students to learn the basics at the core of other languages. MATLAB is not the best language to learn; it is like a car with an automatic gearbox.

MATLAB knowledge can make it harder to shift to another language than having absolutely no programming knowledge.

The IDE and the GUI never force people to think deeply about variables. Keeping a mental model of what the code does, writing down what the code should do, imagining the data structures, and more are necessary skills.

MATLAB explicitly teaches very unorthodox programming principles. Some “features” do not exist in many other languages and certainly not in any language people will likely learn in the future (e.g., Python or C/C++).

MATLAB promotes spaghetti code (see (Vincent, 2017)). According to Brett (2017), some surveys indicate that MATLAB “is unusually bad for beginners.”

MATLAB has no official or formally specified grammar. This paper is about teaching MATLAB to beginners in computer engineering. Programming is significant for

academics and for engineers and computer scientists; however, learning programming is challenging, complex, and requires a wide range of educational tools (Bednarick et al., 2005)(Robins et al., 2003). According to Mutua et al. (2012) , “Teaching and learning programming has over time proved to be a universal problem not only to the students but also to teachers.” Computer science and engineering students have problems mastering programming. According to Thomas et al. (2004), students’ difficulties with programming are “one of the manifestations of a lack of understanding of program behavior.” Understanding program behavior is one of the most important features of learning to program. Visualization has proven effective at providing students with clearer meanings of codes, developing and maintaining programs, and learning programming. Accordingly, works in this area provide a foundation for understanding the behavior of running programs.

Our aim in this paper is to use a recently proposed modeling language called a thinging machine (TM) to improve MATLAB education as an introductory programming language for computer engineers in a computer engineering department. This experiment aimed to achieve in MATLAB what Guest (2017) identifies as “keeping a mental model of what the code is doing, writing down what the code should be doing, [and] imagining the data structures.” We claim that a TM model helps describe program instructions’ composition. A TM allows communication between students and instructors, thereby helping students understand MATLAB and providing a tool for documentation. A TM may have several other benefits in the MATLAB environment, but we focus on the listed objective.

562

Page 3: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

To achieve a self-contained paper, Section II reviews the TM adopted in this paper, which was previously used in several applications in published papers (Al-Fedaghi et al., 2019a-g, 2018a-m). The remaining sections present examples of applying TM to problems taken from the text of a MATLAB course, as described later.

2. Thinging Machine

The notion of thinging originates in Heidegger’s work on The Thing (1975). A TM is an abstract machine with

five generic stages: Create, Process, Release, Transfer, and Receive (as shown in Figure 1). Details on TMs can be

found in the references (Al-Fedaghi, 2019h-j). The generic operations (stages) on things (objects) by machines can be described as follows:

Arrive: A thing arrives at a new machine.

Accepted: A thing enters the machine.

Received: If arriving things are always accepted, then Arrive and Accept can be viewed as a Received stage. For simplification, this paper’s examples assume the received stage structure as shown in Figure 2.

Processed (changed): A thing undergoes some kind of transformation without creating a new thing.

Released: A thing is marked as ready for output outside the machine.

Transferred: A thing is transported somewhere outside the machine.

Created: A new thing is born in the machine. The term Create comes from creativity with respect to a system. Flow among stages (the solid arrows in Figs. 1 and 2) is a spatiotemporal event that signifies a thing’s conceptual

movement from one machine to another or among a machine’s stages. Additionally, the TM model includes memory and triggering (indicated by dashed arrows) relations among the processes’ stages (machines).

2.1 Example

According to Meyer (1997), a sentence in the form “The elevator will close its door before it moves to another floor” would lead a function-oriented designer to detect the need for a “move” function, but an object-oriented designer should see three classes in it: elevator, door, and floor. In a TM, we see four types of machines (Figure 3): the elevator (system) machine, the floor machine, the door machine, and the door’s state submachine.

Figure 4 shows the corresponding TM model that assumes two floors.

Figure 1. A TM.

Create

Receive

Transfer

Release

Process Accept Arrive

Output Input

Figure 2. Simplified TM.

Create

Receive

Transfer

Release

Process

Elevator 1st floor

Figure 3. TM machines in the sentence “The elevator will close

its door before it moves to another floor.”

Door State

Figure 4. The TM model assuming two floors.

Elevator system

Process Release

Receive

Door

Open

Close

Door

Open

Close Release

Transfer

Receive

Transfer

Process

Transfer

Transfer

State

State

1st floor

2nd

floor

1

3

2

4

5 6

7

8 8

9

563

Page 4: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

In Figure 4, assuming a starting point at the first floor with a closed door (circle 1), the elevator will move to the second floor (2). When received at the second floor, it triggers (3) the door to open (4). It is then processed for a period of time, and then it triggers the door to close (5). After closing the door, it is released (6) to move to the first floor (7). Arriving at the first floor triggers (7) the opening of the door (8). There, it is processed (9) for a period of time, and then the door is closed (1).

The elevator system’s behavior is defined via its events. An event in a TM is a machine with at least three submachines: the region where the event occurs, the time, and the event itself. For example, Figure 5 shows the TM model of the event in which the elevator moves from the first floor to the second floor. The events form a hierarchy, starting from the elementary events of stages. We selected the following events while assuming that events are only represented by their regions (see Figure 6).

Event 1 (E1): The elevator is at the first floor with its door closed.

Event 2 (E2): The elevator is moving to the second floor.

Event 3 (E3): The elevator is at the second floor with its door open.

Event 4 (E4): The elevator is at the second floor with its door closed.

Event 5 (E5): The elevator is moving to the first floor.

Event 6 (E6): The elevator is at the first floor with its door open. Figure 7 shows the elevator system’s behavior regarding its events.

2.2 Simplification When Applying TM to MATLAB

When applying TM to MATLAB, we eliminate the Release, Transfer, and Receive stages (see Figure 8) because the arrow directions indicate the flow of the things. The TM diagram is further simplified by eliminating the Process and Create stages, as shown in Figure 9. This figure clearly shows that an arrow that generates a trigger is a Process stage and that an arrow that originates inside the machine is a Create stage. We may also eliminate a machine’s boundary when no ambiguity exists. For example, the state can be eliminated when assuming that the meaning of “open and close the door” is clear. Accordingly, we will denote the simplified TM as STM.

Figure 5. The TM model of the event in which an

elevator moves from the first floor to the second floor.

Elevator

Create Release

Transfer

Receive

Transfer

Process

1st floor

2nd

floor

Region

Release

Transfer

Receive

Transfer

Process (takes its

course

Time The

event

itself

Figure 6. The TM model of events assuming two floors.

Elevator

Process Release

Receive

Door

Open

Close

Door

Open

Close Release

Transfer

Receive

Transfer

Process

Transfer

Transfer

State

State

1st floor

2nd floor

E1

E2 E3

E4

E5

E6

E1 E2 E3 E4 E5 E6

Figure 7. The behavior of the elevator system in terms of the chronology of events.

564

Page 5: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

3. TM Modeling of MATLAB: Interactivity

All the MATLAB examples in this paper are taken from the book A Practical Introduction to Programming and Problem Solving (Attaway, 2009). This is the text used in the author’s MATLAB course, and the STM figures in this paper appear as slides in the freshmen-level course Programming for Engineers. The book first explains a value and a variable in an interactive MATLAB session via an assignment statement. Thus, this section focuses on MATLAB instruction in an interactive session.

(a) Input–output The assignment expression is evaluated, and then the resulting value is stored in the variable. For example,

>> mynum = 6

mynum = 6

>> Figure 10 shows the STM model that describes the execution. For clarity, the figure is repeated with marking numbers in Figure 11. The string “mynum = 6” is the input (circle 1) to be displayed as output (2). By pressing the enter key (3), the execution creates (4) a memory location named “mynum” (5) whereby:

(i) The string “mynum=” is displayed (3), and (ii) the value 6 is stored in the created (6) memory location mynum (7).

Then, the value 6 is output (8).

Figure 9. Further simplification of the TM model.

Elevator

system

Door

Door Open

Close

1st floor

2nd floor

Close

Open

Figure 8. Simplification of the TM model assuming two floors.

Elevator

system

Process

Door

Door Open

Close Process

State

State

1st floor

2nd floor

Create

Close Create

Open

Figure 10. Model of . >> mynum = 6, mynum

= 6.

mynum = 6

“mynum =

6”

Process

mynum

6

Create

System

Variable Value

Memory location

Process ‘mynum

=‘

“mynum =

6”

Assuming:

Input: keyboard

Output: screen

“6”

Enter

Process (extract)

6

“mynum=”

Figure 11. Model of . >> mynum = 6.

mynum = 6

“mynum =

6”

Process

mynum

6

Create

System

Process “mynum

=”

“mynum

=6”

“6”

Enter

Process (extract)

6

“mynum=”

1

2

3

4

5

6

7

8

565

Page 6: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

Figure 12 shows the selected events as follows: Event 1 (E1): Receiving the input. Event 2 (E2): Displaying the input. Event 3 (E3): Pressing enter. Event 4 (E4): Displaying the non-value part of the input. Event 5 (E5): Storing the variable’s value. Event 6 (E6): Outputting the value.

Figure 13 shows the chronology of these events in the given example. When shown to students, these slides hardly need further elaboration.

(b) Suppressing output Putting a semicolon at the end of a statement suppresses the output. For example, Figure 14 shows >> mynum = 9–2;

Figure 14 contrasts with the previous example.

(c) Without suppression

Suppose that, after initializing the mynum to 6, we enter >>mynum = mynum +1 mynum = 7

Figure 15 shows the corresponding STM representation. The events are selected as follows (see Figure 16): Event 1 (E1): Receiving the input. Event 2 (E2): Displaying the input. Event 3 (E3): Pressing Enter. Event 4 (E4): Displaying part of the input. Event 5 (E5): Incrementing mynum by 1. Event 6 (E6): Outputting a value of a variable.

Figure 17 shows the chronology of these events in the given example.

E1

E2

E3 E5 E6

E4

Figure 13. The chronology of events in .>> mynum = 6.

mynum = 6

Figure 14. Model of . >> mynum = 9 − 2.

mynum = 6

“mynum = 9 − 2;”

Process

mynum

7

Create

System “mynum = 9 − 2;”

Enter

Process (Extract and calculate)

“mynum =

mynum + 1”

Figure 15. Model of . >> mynum = mynum +

1.

mynum = 6

“mynum =

mynum + 1”

Process

mynum

System

Process “mynum

=”

“7”

Enter

Process (extract)

mynum + 1

“mynum = ”

Process

add 1 6 7

Figure 12. Model of . >> mynum = 6.

mynum = 6

“mynum =

6”

Process

mynu

m

6

Create

System

Process “mynum

=”

“mynum =

6”

“6”

Enter

Process (extract)

6

“mynum

=””

E1

E3

E4

E2

E6

E5

566

Page 7: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

(d) Who In MATLAB, Who shows variables defined in the Command Window. Figure 18 shows the semantics of who. The

system contains a file with variables’ names. Who triggers the processing of the file and the extraction of each name to be output. Here, the instructor can explain that the figure’s Process stage extracts the variable names one by one to be output. Figure 19 shows the events in Figure 18. Figure 20 shows the chronology of events. Note that the loop of extracting the names in the file is specified in the behavior diagram (Figure 19). For simplicity, we will not display the input instructions in the TM diagrams in the rest of the paper. Similarly, we

will not include the ENTER trigger.

(e) Built-in Functions Consider the trigonometry function sin(1.4), as in

>> 2 * sin(1.4)

ans =

.9709

Figure 21 shows its STM model.

E1

E2

E3 E4

E5 E6

Figure 17. The chronology events in >> mynum =

munum+1.

mynum = 6

“mynum =

mynum + 1”

“mynum

=”

Figure 16. Model of . >> mynum = mynum + 1.

mynum = 6

Process

mynum

System

Process

“7”

Enter

Process (extract)

Mynum + 1

“mynum=”

Process

add 1 6 7

“mynum =

mynum + 1” E1

E2

E3

E4

E5

E6

“who”

Life (list)

of all

variables

names

System

Process

Enter

Variable name

Create

“who”

Process

Figure 18. Model of Who.

mynum = 6

Figure 19. Model of events of Who.

mynum = 6

“who”

Enter

“who”

Life (list)

of all

variables

System

Process: read from

file

Variable name

Create

Process

E1

E2 E3

E1 E2 E3

Figure 20. Chronology of events in

Who.

mynum = 6

Until end of

file

myn

um = 6

sin()

“2 * sin(1.4)”

System

Ans

Create

Process

Figure 21. Model of 2 * sin(1.4).

mynum = 6

1.4 Process

Value

2

Process: multiplication

Create

567

Page 8: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

4. Vectors and Matrices

The matrix is a fundamental structure of MATLAB [4] and follows the FORTRAN matrix style.

(a) Supplying Values of a Vector

The most direct way to supply a vector’s values is to put them in square brackets separated by either spaces or

commas.

>> v = [1 2 3 4]

v =

1 2 3 4

Figs. 22, 23, and 24 show the corresponding STM model, the events, and the chronology of event figures,

respectively. It is possible to model a vector as an i-dimensional matrix.

(b) Empty Vector An empty vector is a vector that stores no values. It can be created using empty square brackets: >> evec = []

evec = []

Figure 25 shows the TM model of an empty vector. Values can be added by adding values to the existing vector. The following statement takes what is currently in

evec, which is nothing, and adds the value 4 to it (see Figure 26): >> evec = [evec 4]

evec = 4

“v = [1 2 3 4]” System

v

Create

Figure 22. Model of v = [1 2 3 4].

mynum = 6

Process

Length

Create

1 2 3 4

4

Process

“v = [1 2 3 4]”

Figure 23. Events of v = [1 2 3 4].

mynum = 6

E1

m

ynum

= 6

System

v

Create

Process

Length

Create

1 2 3 4

4

Process

E2

m

ynum

= 6

E3

m

ynum

= 6

E4

m

ynum

= 6

E5

m

ynum

= 6 E6

m

ynum

= 6

E1 E2 E3

Figure 24. Chronology of events in v = [1 2 3 4].

mynum = 6

E4

E6

E5

“evec = []”

System

evec

Create

Figure 25. Model of evec = [].

mynum = 6

Process

Length

Create 0

Process

System

evec

Create

Figure 26. Model of evec = [evec 4].

mynum = 6

Process

Length

Create 1

Process

“evec = [[evec 4]]”

4

568

Page 9: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

(c) Random Numbers

Matrices of random numbers can be created using the randint function. The first two arguments of the randint

function specify the random-integer matrix’s size. For example, the following will create a 2 × 4 matrix of random

integers in a range from 10 to 30:

>> randint(2,4,[10,30])

ans =

29 22 28 19

14 20 26 10

Figure 27 shows the semantics of this use of randint. First, randint(2,4,[10,30]) is processed (1) to

(i) create the matrix v (2) with its numbers in rows (3) and in columns (4) and store its eight values, and

(ii) trigger randint (5) to generate the random numbers to be stored in their locations (6) in v.

Lastly, the matrix is output (7). Note that the matrix elements are stored in columns

Accordingly, the events can be selected (see Figure 28) as follows:

Event 1 (E1): Receiving randint(2,4,[10,30] and processing it.

Event 2 (E2): Constructing the matrix v.

Event 3 (E3): Triggering randint to generate eight values and store them in v. Event 4 (E4): Displaying the matrix.

Figure 29 shows the chronology of these events in the given example.

5. Scripts and Programs

In this section, we will show how the MATLAB program consists of combinations of scripts and user-defined

functions.

(a) Input

Consider the problem of calculating a circle’s area. First, given the radius, the circle’s area would be calculated.

The basic algorithm is:

1. Get the radius input.

2. Calculate the result: the area.

3. Display the output (Attaway, 2009).

6

“randint = (2, 4, [10, 30])]”

System

v

Create

Figure 27. Model of randint(2,4,[10,30]).

Process

r

Create

c

29 14 22 20

2

4 Create

Process

28 26 19 10

randint

Create

Process [10,30]

1

2

3

4

5

6

7

“randint = (2, 4, [10, 30])]”

Figure 28. The events of randint(2,4,[10,30]).

System

v

Create

Process

r

Create

c

29 14 22 20

2

4 Create

Process

28 26 19 10

randint

Create

Process [10,30]

E1

E2

E3

E4

E1 E2 E3 E4

Eight times

Figure 29. The chronology of events of randint(2,4,[10,30]).

569

Page 10: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

Here, we must introduce the notion of a script as a sequence of MATLAB instructions stored and saved in a file.

Scripts will be displayed in a box with the name on top (Attaway, 2009) as flows for calculating the area. It assigns

a value for the radius and then calculates the area based on that radius. In this text, script1 is displayed in a box with

the name on top.

>> script1

radius = 5

area = 78.5398 Figure 30 shows the STM model of script1. The input is processed (1) to store the given value of radius (2).

Then radius, pi (3), and the constant 2 (4) are used to calculate pi* (radius^2) (5) and create the result, which is

stored in area (6). Lastly, the area is output (7).

The events of script1 are selected (see Figure 31) as follows:

Event 1 (E1): Receiving input and storing the value in radius.

Event 2 (E2): Retrieving radius.

Event 3 (E3): Retrieving pi.

Event 4 (E4): Retrieving 2.

Event 5 (E5): Using radius, pi, and 2 to calculate pi * (radius^2).

Event 6 (E6): Storing the result in area.

Event 7 (E7): Displaying the area. Figure 32 shows the chronology of these events in the example.

(b) Input Function

The simplest input function in MATLAB is called input. The input function is used in an assignment statement.

For example,

>> rad = input(‘Enter the radius: ’)

Enter the radius: 5

rad = 5

Figure 33 shows the TM model, and Figure 34 shows the corresponding Events.

radius = 5

area = pi * (radius^2)

script1.m

Figure 31. Model of script1.

mynum = 6

Create area

Process

value radius

Constant

Process: pi * (radius^2)

2

Script1

pi 3.141592653589793

E1

E3 E2 E4 E5

E6 E7

E1

E2

E3

E4

Figure 32. The chronology of events of script1.

E5 E6 E7

Script1

Figure 30. Model of script1.

mynum = 6

Process

value radius

value pi 3.141592653589793

Process: pi * (radius^2)

Constant

2

Create area

1

2 3

4

5

6 7

570

Page 11: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

6. Teaching Programming

As mentioned in the introduction, this paper aims to facilitate a deeper understanding of MATLAB. In this

subsection, we show a glimpse of using a TM to program. With scripts, it is now possible to start teaching

programming.

(a) Scripts

Consider writing script to calculate and return the product of the integers from m to n. Thus, the result for m=3

and n=8 would be 3 * 4 * 5 * 6, or 360 (Attaway, 2009). We use the STM diagram to construct the solution’s

“elementary” steps. First, m and n are input using the input function, as shown in Figure 35.

Then, the student was asked to do the initial step in calculating the product. The answer was multiplying m by

m+1. We decided not to mess up the original value of m by using the variable i for different values of m. We

discovered that we need another variable to store the product, such as prod1. In general we need to do the following:

(1) Put m in I, (2) Calculate i*i+1 and put the result in prod1, and (3) Calculate prod1*i and put the result in prod1.

It is not difficult to persuade the students to make steps 2 and 3 into one step by initializing prod1 as 1. Accordingly,

we reach the description shown in Figure 36.

Now, we clearly need (i) a loop to repeat E3 and (ii) a method to stop the loop. The final solution is seen in

Figure 37. The students were almost surprised to see the MATLAB instruction

for i = m:n prod1 = prod1 * i; end accomplishes the same thing with respect to the loop.

Figure 33. Model of . >> rad = input(‘Enter the radius: ’)

mynum = 6

rad =

input(‘Enter the

radius: ’)

Process

rad

5

Create

System

‘Enter the

radius:’

“5”

Process

‘Enter the radius:’

input

‘Rad =’

Process

“5”

E4

E6

E3

E2

E5

Figure 34.Events of . >> rad = input(‘Enter the radius: ’)

mynum = 6

rad =

input(‘Enter

the radius: ’)

Process

rad

5

Create

System

‘Enter the

radius:’

“5”

Process

‘Enter the radius:’

inpu

t

‘Rad =’

Process

“5”

E1

E7

Figure 36. Step 2 in developing the product’s algorithm.

E2

E3

Process: prod1 * i

i

m n

Process

Prod1

Create

Constant 1

m n

Process

Figure 37. The final touches in the product algorithm.

Process: prod1 * i

i Constant 1 Process

Increment prod

Create

If i==n stop

E4

E5

m n

Process

Figure 35. First step in constructing the product

algorithm.

mynum = 6

571

Page 12: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

(b) Functions

Consider how to write the function prod1_m_to_n to calculate and return the product of the integers m and n

without assuming a specific order of the arguments. This is similar to the previous exercise, except we use a

function, and the values of m and n do not have specific order.

Figure 38 shows this function’s corresponding STM model.

(c) Nested Loop

The book Practical Introduction to Programming and Problem Solving (Attaway, 2009) defines a nested loop

as when “the action” of a loop is another loop, as when a nested for loop prints a box of asterisks. For example, the

output when rows has the value 3 and columns has the value 5 would be:

*****

*****

*****

printstars.m

The action is looped to one line, and then the new line’s character is printed after all five stars to move the cursor

down to the next line.

Figure 39 shows the STM solution. First, i and j are initialized to 1 (circles 1 and 2). J (3) and rows (4) are

compared (5). If j is equal or less than rows, then * is output (6) and j is incremented (7). If j is greater than rows at

the end of this process (8), then a new line is output (9). Then, i is incremented (10), and i and columns are

compared (11). If i is equal or less than columns, then j is initialized again to 1 (12). If i is greater than columns, then

a new line is output (13).

The dark box in Figure 39 clearly models the inner loop. Figure 40 shows the execution relationship between the

inner and outer loops. Figure 41 shows the events in the printstars model, and Figure 42 shows the model’s

behavior.

function prod1 =

prod1_m_to_n(m,n) if m > n temp = m; m = n; n = temp; end

prod1 = 1;

for i = m:n prod1 = prod1 * i; end

prod_m_to_n.m

Process:

If m>n

temp

Figure 38. The STM model of prod1= prod_m_to_n(m,n).

1

m n

Process:

2 3 4

5

Process: prod1 * i

i Constant 1 Process

Increment Prod1

Create

If i==n stop

The two input values are compared to determine (1)

whether to store the smaller and larger values in m (2) or

in n (3), respectively. Note that process (4) of exchanging

values appears almost as a locally independent process

that is triggered or activated (5) when m is greater than n.

The product is then calculated, as in the previous example.

for i=1:rows for j=1:columns

fprintf(‘*’)

end

fprintf(‘\n’)

end

572

Page 13: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

5. Conclusion

This paper proposed utilizing the TM model in computer engineering to facilitate understanding MATLAB instructions. The preliminary findings are encouraging. TM presents a new and viable approach in visualizing programs in the programming domain in general. Further research would expand on using TM to write diagrams as explored briefly in section 5.C.

References Al-Fedaghi S. and Aldamkhi, G., Conceptual modeling of an IP phone communication system: A case study, 18th

Annual Wireless Telecommunications Symposium (WTS 2019), New York City, New York, USA, April 9–12,

2019a.

Al-Fedaghi S. and Alkhaldi, A., Thinging for computational thinking, Int. J. Adv. Comput. Sci. Appl., vol. 10, no. 2,

pp. 620–629, 2019b.

Al-Fedaghi S. and Atiyah, Y., Modeling with thinging for intelligent monitoring system, IEEE 89th Vehicular

Technology Conference: VTC2019-Spring, Kuala Lumpur, Malaysia, April 28–May 1, 2019c.

Figure 39. The STM model of printstars.

If j ≤ columns Process: If j > columns

rows

Constant 1

*

j i Process: increment

If i ≤ rows Process: If i > rows

Process: increment

Columns

\n

2

1

5

3 4

7

6

8

9

10

Constant 1

11

12

13

Figure 41. The events of STM model of printstars.

If j ≤ columns Process: If j >columns

rows

Constant 1

*

j i Process: increment

If i ≤ rows Process: If i > rows

Process: increment

Columns

\n

Constant 1

E1

E2

E7

E3

E4

E5

E5 E6

E1 E2 E3 E5

Figure 42. The chronology of events of printstars.

E4

E7 E6

for j=1:columns

fprintf(‘*’)

end

for i=1:rows

fprintf(‘\n’)

end

Figure 40. The execution relationship between

the inner and outer loop.

573

Page 14: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

Al-Fedaghi S. and Hassouneh, A., Modeling the engineering process as a thinging machine: A case study of chip

manufacturing, The 8th Computer Science Online Conference (CSOC 2019), Springer Advances in Intelligent

Systems and Computing, pp 67-77, vol. 986. Springer, Cham, 2019d.

Al-Fedaghi S. and Al-Otaibi, M., Service-oriented systems as a thinging machine: A case study of customer

relationship management, IEEE International Conference on Information and Computer Technologies (ICICT),

University of Hawaii, Maui College, Kahului, Hawaii, USA, March 14–17, 2019e.

Al-Fedaghi S. and Haidar, E., Programming is diagramming is programming, 3rd International Conference on

Computer, Software and Modeling, Barcelona, Spain, July 14–16, 2019f.

Al-Fedaghi S. and Al-Fadhli, J., Modeling an unmanned aerial vehicle as a thinging machine, 5th International

Conf. on Control, Automation and Robotics (ICCAR 2019), Beijing, China, April 19–22, 2019g.

Al-Fedaghi, S., Five Generic Processes for Behaviour Description in Software Engineering, Int. J. Comput. Sci. Inf.

Secur., vol. 17, no. 7, pp. 120–131, July 2019h.

Al-Fedaghi, S., Thing/machine-s (thimacs) applied to structural description in software engineering, Int. J. Comput.

Sci. Inf. Secur., vol. 17, no. 8, August 2019i.

Al-Fedaghi, S., Toward maximum grip process modeling in software engineering, Int. J. Comput. Sci. Inf. Secur.,

vol. 17, no. 6, pp. 8–18, June 2019j.

Al-Fedaghi S. and Atiyah, Y., Tracking systems as thinging machine: A case study of a service company, Int. J.

Adv. Comput. Sci. Appl., vol. 9, no. 10, pp. 110–119, 2018a.

Al-Fedaghi S. and Al-Huwais, N., Enterprise asset management as a flow machine, Int. J. Model. Optim., vol. 8, no.

5, pp. 290–300, October 2018b.

Al-Fedaghi S. and Al-Huwais, N., Toward modeling information in asset management: Case study using Maximo,

4th International Conference on Information Management (ICIM2018), Oxford, UK, May 25–27, 2018c.

Al-Fedaghi S. and BehBehani, M., Thinging machine applied to information leakage, Int. J. Adv. Comput. Sci.

Appl., vol. 9, no. 9, pp. 101–110, 2018d.

Al-Fedaghi S. and Al-Huwais, N., Conceptual modeling of inventory management processes as a thinging machine,

Int. J. Adv. Comput. Sci. Appl., vol. 9, no. 11, November 2018e.

Al-Fedaghi S. and Al-Otaibi, M., Conceptual modeling of a procurement process: Case study of RFP for public key

infrastructure, Int. J. Adv. Comput. Sci. Appl., vol. 9, no. 1, January 2018f.

Al-Fedaghi S. and Alnasser, H., Network architecture as a thinging machine, Symposium on Mobile Computing,

Wireless Networks, & Security (CSCI-ISMC), Las Vegas, NV, USA, December 13–15, 2018g.

Al-Fedaghi S. and Alsulaimi, M., Re-conceptualization of IT services in banking industry architecture network, 7th

IEEE International Conference on Industrial Technology and Management (ICITM 2018), Oxford University,

Oxford, UK, March 7–9, 2018h.

Al-Fedaghi S. and Al-Azmi, R., Control of waste water treatment as a flow machine: A case study, The 24th IEEE

International Conference on Automation and Computing (ICAC ‘2018), Newcastle University, Newcastle upon

Tyne, UK, September 6–7, 2018i.

Al-Fedaghi S. and Bayoumi, M., Computer attacks as machines of things that flow, International Conference on

Security and Management (SAM’18), Las Vegas, NV, July 30–August 2, 2018j.

Al-Fedaghi S. and Warsame, N., Provenance as a machine, International Conference on Information Society (i-

Society), Dublin, Ireland, July 15–18, 2018k.

Al-Fedaghi S. and Alsulaimi, M., Re-conceptualization of IT services in banking industry architecture network, 7th

IEEE International Conference on Industrial Technology and Management (ICITM 2018), Oxford University,

Oxford, UK, March 7–9, 2018l.

Al-Fedaghi S. and Esmaeel, A., Modeling digital circuits as machines of things that flow, International Conference

on Mechatronics Systems and Control Engineering (ICMSCE 2018), Amsterdam, Netherlands, February 21–23,

2018m.

Al-Fedaghi, S., Thinging for software engineers, Int. J. Comput. Sci. Inf. Secur., vol. 16, no. 7, pp. 21–29, July

2018n.

Attaway, S., A Practical Introduction to Programming and Problem Solving, 4th ed. Burlington, MA: Butterworth–

Heinemann, 2009.

Bednarick, R., Moreno, A., Myller N. and Sutinen, E., “Smart program visualization technologies: planning a next

step,” Fifth IEEE International Conference on Advanced Learning Technologies, 2005.

Brett, M., Comparing Python and Matlab for teaching in science, Asterisk, November 8, 2017,

http://asterisk.dynevor.org/python-matlab.html

Computer Hope, MATLAB. https://www.computerhope.com/ jargon/m/matlab.htm (accessed June 30, 2019).

574

Page 15: Thinging MATLAB for Computer Engineering · Computer science and engineering departments often choose a language for the lessons it can teach about programming languages, rather than

Proceedings of the International Conference on Industrial Engineering and Operations Management

Riyadh, Saudi Arabia, November 26-28, 2019

© IEOM Society International

Cohen, M., What is MATLAB and who needs it? Learn Programming. https://learnprogramming.academy

/programming/what-is-matlab-and-who-needs-it/ (accessed Aug. 26, 2018).

Dori, D., Renick, A. and Wengrowicz, N., When quantitative meets qualitative: enhancing OPM conceptual systems

modeling with MATLAB computational capabilities,” Research in Engineering Design, vol. 27, no. 2, pp. 1–

23, December 2015.

Downey, A. B., Physical Modeling in MATLAB, Version 3.0.0, Needham, MA: Green Tea Press, 2019,

http://greenteapress.com/ matlab/PhysicalModelingInMatlab3.pdf

Guest, O., I hate Matlab: How an IDE, a language, and a mentality harm, Neuroplausible Blog, March 17, 2017,

https://neuroplausible.com/matlab

Heidegger, M., The thing, in Poetry, Language, Thought, A. Hofstadter, Trans. New York: Harper & Row, 1975, pp.

161–184.

McKeeman, B., MATLAB 101—A talk for the MIT Computer Science Department, November 9, 2005.

https://www.cs.dartmouth.edu/~mckeeman/references/matlab101/matlab101.html

Meyer, B., Object-Oriented Software Construction, 2nd ed. USA: Prentice Hall Professional Technical Reference,

1997.

Mutua, S., Wabwoba, F., Ogao, P., Anselmo, P. and Abenga, E., Classifying program visualization tools to facilitate

informed choices: teaching and learning computer programming, Int. J. Comput. Sci. Telecommun., vol. 3, no.

2, February 2012.

Nikonov, D., Matlab DOs and DON’Ts, Intel, Slides, May 6, 2006.

https://nanohub.org/local/ipod/Nikonov_NANO501_Matlab_Dos_and_Don'ts(PDF).pdf

Rath, N., MATLAB is a terrible programming language, SUN, September 17, 2017, http://www.rath.org/matlab-is-

a-terrible-programming-language.html

Robins, A., Rountree, J. and Rountree, N., Learning and teaching programming: a review and discussion, Comput.

Sci. Educ., vol. 13 no. 2, 2003.

Thomas, L., Ratcliffe, M. and B. J. Thomasson, Can object (instance) diagrams help first year students understand

program behaviour?, A.F. Blackwell, K. Marriott, and A. Shimojima, Eds. Diagrammatic Representation and

Inference. Diagrams 2004. Lecture Notes in Computer Science, vol 2980. Springer, Berlin, Heidelberg, pp.

368–371, 2004.

Vincent, B. T., Matlab rant 2, Inference Lab, March 17, 2017, http://www.inferencelab.com/matlab-rant-2/

Biography: Sabah Al-Fedaghi is an associate professor in the Department of Computer Engineering at Kuwait

University. He holds an MS and a PhD from the Department of Electrical Engineering and Computer Science,

Northwestern University, Evanston, Illinois, and a BS in Engineering Sciences (computer) from Arizona State

University. He has published more than 320 journal articles and papers in conferences on Software Engineering,

Database Systems, information Ethics, Privacy and Security. He previously worked as a programmer at the Kuwait

Oil Company and headed the Electrical and Computer Engineering Department (1991–1994) and the Computer

Engineering Department (2000–2007).

575