0% found this document useful (0 votes)
77 views

Computational Science and Numerical Methods-1

This document describes a course on computational science and numerical methods. It contains: 1. An introduction to computational science explaining the experimental, theoretical, computational, and data science approaches to problem solving. 2. An outline of the course contents including operation research, numerical computation, graphical computation, modelling and simulation, and high performance computation. 3. A section on different types of models that can be used in computational science, classified by criteria like mathematical models, optimization models, probabilistic models, and models using different mathematical techniques.

Uploaded by

daily feast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Computational Science and Numerical Methods-1

This document describes a course on computational science and numerical methods. It contains: 1. An introduction to computational science explaining the experimental, theoretical, computational, and data science approaches to problem solving. 2. An outline of the course contents including operation research, numerical computation, graphical computation, modelling and simulation, and high performance computation. 3. A section on different types of models that can be used in computational science, classified by criteria like mathematical models, optimization models, probabilistic models, and models using different mathematical techniques.

Uploaded by

daily feast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E.

Oguike

CSC311, Computational Science and Numerical Methods


Asso. Prof. Oguike, Osondu Everestus
Department of Computer Science and Mathematics,
Godfrey Okoye University of Nigeria,
Enugu

Course Contents
1. Operation Research
2. Numerical Computation
3. Graphical Computation
4. Modelling and Simulation
5. High Performance Computation

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 1


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

1 Introduction to Computational Science


1.0 Introduction
Scientists can solve problems, using different approaches, which includes the following:
Experimental Science, Theoretical Science, Computational Science and Data Science.
Experimental science involves the use of laboratory tools to perform physical experiments, which
involves changing the values of a particular variable (input variable), while other variables remain
constant, with the aim of obtaining the result of another variable (output variable). Different trials
of this experiment can be performed with different input variables in order to obtain various output
variables. The results of the different trials of the experiment can be plotted i.e. output variable
against input variable, with the aim of understanding the relationship between the two variables.
The theoretical science approach to problem solving does not involve any form of physical
experiments. The thirds approach to problem solving is computational science, which involves the
development of models that represent the description of a particular system (modelling); the models
in most cases can be mathematical models, though, not always. The developed models can be
represented on the computer and executed. The computer representation of the developed model is
called simulation model, while the process of executing the simulation model (program) is called
simulation. The fourth approach is the data science approach, which solves problems using large
collection of data, called training data. In data science, the solution to the problem depends on the
data, rather than on the model or algorithm. Data science combines statistical tools with machine
learning models, in order to solve a particular problem.
In this course, different models that describe different systems, which have been developed will be
considered, and the algorithms that can be used to evaluate or solve the model will be presented,
together with the simulation model for the evaluation and solution to the model will be presented.

1.1 Different Types of Models


There are different types of models, which can be classified using the following criteria:
mathematical, optimization, probabilistic, mathematical techniques etc. This section uses each of
the criterion to identify the different classes/types of model.

• Mathematical: Though most models are mathematical models, however, some models are
not mathematical model. This criterion identifies two different types of models, which are:

1. Mathematical Models:

These are models that models that are mathematical in nature.

2. Non Mathematical Models:

These are models that are not mathematical in nature, they can be inform of diagrams or
tables.

• Optimization: This criterion distinguishes models, which are used to solve optimization
problems, from models that are used to solve non optimization problems. Using this
criterion, the following are the different types of model.

1. Optimization Models:

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 2


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

These are models, which are used to solve optimization or operation research problems.
They are called optimization models because they aim at determining the best or optimum
way of doing things.

2. Non-Optimization Models:
Non optimization models do not aim at determining the best or optimum way of doing
things, rather, they are just predictive in nature.

• Probabilistic: In order to take care of errors that could occur in the development of the
models, this criterion help to distinguish between models that are probabilistic in nature or
not. The following models can be distinguished using this criterion.

1. Probabilistic/Stochastic Model:

These are models that are developed using the statistical concept of probability. The reason
for this type of model is because of the error associated in the development of the
mathematical model.

2. Non Probabilistic/Non Stochastic Model:

Non probabilistic/Non Stochastic Model are model that are developed without the use of
the statistical concept of probability theory,

• Mathematical Techniques: Different mathematical techniques can be used to develop


different type of models, which leads to the following types of models:

1. Linear Model:

All the mathematical models in this types of model are in linear form. The maximum power
of the variables is 1.

2. Non Linear Model:

All the mathematical models in this type of models are not in linear form, which means that
the maximum power of the variables is more than 1.

3. Ordinary Differential Equation Models:

These are the type of model, which contains ordinary differential equations/expressions.

4. Partial Different Equation Model:

These are the type of model, which contains partial differential equations/expressions.

5. Integral Equation Models:

These are models that contain integral equations/expressions.

2. Optimization/OR Models
Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 3
November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

2.0 Introduction
Optimization models or sometimes called operation research models are models that are use to
solve optimization or operation research problems. There are different types of
optimization/operation research models that solve different optimization/operation research
problem, they include the following:

2.1 Linear Programming Models


Linear programming model is one of the fundamental operation research models, which are used
to solve linear programming problem. The model has two parts, which are: objective function part
and the constraint part. The objective function part contains a single linear function, the aim is to
maximize or minimize the objective function. The constraint part contains one or more linear
constraints. The overall aim of the linear programming model is to minimize or maximize the
objective function, subject to the various constraints. The process of representing a real life problem
into a linear programming model is called formulating or modelling a linear programming model.
This involves translating the description of the system into equivalent linear mathematical
representation. An example of linear programming problem is shown below:

Maximize Z = 3x + 5y
Subject to: 2x– 6y <= 21
4x+ 7y <= 4 (1)
x >= 0
y >= 0

2.1.1 Formulating/Modelling Linear Programming Problem

The following example will illustrate how to represent a real life description of a problem as a linear
programming model:
Example 1:
An Industrial Chemist produces both interior and exterior paints from two raw materials, M1 and
M2, The following table provides the basic data of the problem:

Exterior Paints Interior Paints Daily Max. Availability


Raw Material, M1 6 4 24
Raw Material, M2 1 2 6
Profit/Ton 5 4

A marketing survey restricts the maximum daily demand of interior paints to 2 tons. Additionally,
the daily demand for Interior paints cannot exceed that of Exterior paints by more than 1 ton. The
Industrial Chemist wants to determine the optimum product mix of Interior and Exterior paints that
maximizes the total daily profit.
The first thing to do is to model the problem as a linear programming problem. The following steps
will be followed in order to represent the problem as a linear programming problem:

1. Represent the desired quantities as variables, which we call Basic variables.

From the description, the desired quantities are the number of Exterior and Interior paints
that the Industrial Chemist will produce in order to maximize profit. Therefore, let x be the

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 4


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

number of Exterior paint, and let y be the number of Interior paint to produce in order to
maximize profit.

2. Model the Objective function:

In order to model the objective function, you need to simply translate the detail description
into a mathematical expression. However, where a tabular representation is provided, you
need to use the table to formulate the objective function.
In the example that is before you, the problem has been presented in tabular form, therefore,
to form the objective function, your aim will be to maximize profit. Since you have assigned
x to the number of Exterior paint to produce and y to be the number of Interior paint to
produce, from the table, you can obtain the total profit from both Exterior and Interior paint
as 5x + 4y, therefore, the objective function will be:
Maximize Z = 5x + 4y

3. Model the Various Constraints:

The tabular representation will be very useful in doing this and any other description of the
problem. From the tabular representation, you can obtain the total tons of raw material M1
and M2 as 6x + 4y, since this must be less than or equal to the daily availability of 24, you
can write the first constraint as follows:
6x + 4y <= 24
Similarly, for the second raw material, M2 as shown in the table, you can write the second
constraint as:
x + 2y <= 6
Furthermore, from the description of the problem, “A marketing survey restricts the
maximum daily demand of Interior paint to 2 tons”, this can be expressed mathematically
as: y <= 2. “Additionally, the daily demand for Interior paint cannot exceed that of Exterior
paint by one than 1 ton.” This can be expressed mathematically as follows:
y <= x + 1
Combining the objective function and all the constraints, the following are the various
constraints:
Maximize Z = 5x + 4y
Subject to: 6x + 4y <= 24
x + 2y <= 6
y <= 2
-x + y <= 1
x >= 0
y >= 0

After the modelling the linear programming model, the next thing is to determine the optimal
solution to the linear programming. The optimal solution to the linear programming problem in (1),
is to find the values of x and y, which will maximize the objective linear function, such that the four
set of constraints are satisfied. There are different methods, which can be used to determine the
optimal solution to linear programming problem, one of the methods is the Simplex
method/Simplex algorithm.

2.1.2 Simplex Method/Algorithm for Solving the Linear Programming Problem


The following is the simplex algorithm, which can be used to determine the optimal solution to the
linear programming problem.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 5


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

1 Introduce slack and surplus variables to the constraints:


2 Form the initial tableau
3 Perform optimality test to select pivot column
4 Calculate the value of alpha.
5 Perform feasibility test to select the pivot row.
6 Form one row of the new tableau.
7 Compute the various elements of the new tableau.
8 Repeat steps 3, 4, 5, 6 and 7 until all the columns of the basic variables have been
selected as the pivot column
Each of the steps of the simplex algorithm will be explained and applied to the Industrial Chemist
problem.

1. Introduce Slack and Surplus Variables to the Constraints.


Slack variables are variables that you add to the left hand side of the constraints in order to
remove the “less than sign”, so that the inequality sign will become “equals” sign, while
surplus variables are variable that you subtract from the left hand side of the constraints in
order to remove the “greater than sign”, so that the inequality sign will become “equals”
sign. When you introduce slack and surplus variables to the Industrial Chemist linear
programming problem, the linear programming problem becomes:

Maximize Z = 5x + 4y
Subject to: 6x + 4y + a + 0 + 0 + 0= 24
x + 2y + 0 + b + 0 + 0= 6
-x + y + 0 + 0 + c + 0 = 1
0 + y+0 +0+0+ d=2

2. Form the initial tableau.


You form the initial tableau by arranging the linear programming problem in a tabular form.
The constraints form the rows of the initial tableau, while the objective function forms the
z row of the initial tableau. The initial tableau of the linear programming problem consists
of the coefficients of the basic, slack and surplus variables. The initial tableau of the
Industrial Chemist linear programming problem follows below:

x y a b c d Solution
1 6 4 1 0 0 0 24
2 1 2 0 1 0 0 6
3 -1 1 0 0 1 0 1
4 0 1 0 0 0 1 2
Z -5 -4 0 0 0 0 0

3 Perform Optimality Test, to Select the Pivot Column.


The pivot column, PC is the column of the initial tableau, which has the highest negative
element in the z row. In the Industrial Chemist linear programming problem, the pivot
column of the initial tableau is the first column, this is because its z element of -5 is the
highest negative element in the z row. In choosing the pivot column, you must limit yourself
to the column of the basic variables. Using the Industrial Chemist linear programming
problem, the pivot column is shown below.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 6


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

X Y A B C D Solution
1 6 4 1 0 0 0 24
2 1 2 0 1 0 0 6
3 -1 1 0 0 1 0 1
4 0 1 0 0 0 1 2
Z -5 -4 0 0 0 0 0

4. Calculate the Value of Alpha.


In order to calculate the value of alpha in each row of the tableau, you divide the solution column
with each of the corresponding element of the pivot column, excluding the z row.

5. Perform the Feasibility Test by Selecting the Pivot Row.


The pivot row is the row with the smallest positive alpha element, excluding zero and infinity,
while the pivot element is the element that intersects the pivot row and the pivot column. In the
Industrial Chemist linear programming problem, the selection of the pivot row and pivot
element is shown below.

x y A B C D Solution Alpha
1 6 4 1 0 0 0 24 4
2 1 2 0 1 0 0 6 6
3 -1 1 0 0 1 0 1 -1
4 0 1 0 0 0 1 2 inf
Z 5 -4 0 0 0 0 0

6. Form One Row of the New Tableau

In order to form one of the rows of the new tableau, simply divide each element of the pivot
row by the pivot element, to form the corresponding row for the new tableau. Using the
Industrial Chemist linear programming problem, the table below shows the first row of the new
tableau.

x y A B C D Solution Alpha
1 1 4/6 1/6 0 0 0 4
2 0 4/3 -1/6 1 0 0 2
3 0 5/3 0 0 1 0 5
4 0 1 0 0 0 1 2
Z 0 -4/6 5/6 0 0 0 20

7. Compute the Various Elements of the New Tableau


The table below can be used as a guide to computing the various elements of the new tableau.

Row 2 Row 3 Row 4 Z Row


1 Old element 1201006 -1100101 0100012 -5-400000
2 PC element 1111111 -1-1-1-1-1-1-1 0000000 -5-5-5-5-5-5-5
3 No 1 New element 14/61/60004 14/61/60004 14/61/60004 14/61/60004
4 2x3 14/61/60004 1-4/6-1/6000-4 0000000 -5-20/6-5/6000-20
5 1-4 04/3-1/61002 05/31/60105 0100012 0-4/65/600020

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 7


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

8. Repeat steps 3, 4, 5, 6 and 7 until all columns of the basic variables have been selected as
pivot column.

After the repetition, the final tableau is shown below.

x y A B C D Solution
1 1 0 ¼ -1/2 0 0 3
2 0 1 -1/8 ¾ 0 0 3/2
3 0 0 9/24 -5/4 1 0 5/2
4 0 0 1/8 -3/4 0 0 ½
Z 0 0 3/4 1/2 0 1 21

From the final tableau, you can easily read the values of x and y and the optimal value, z. To do
this, trace the solution value for the row where the basic variables are 1. When yo do this, the basic
variables values will be, x = 3 and y = 3/5, and the optimal value of z = 21. This solution is the
same as the result obtained from the simulation model in Python.

2.1.3 Simulation Model for the Linear Programming Problem


Different software tools can be used to represent the linear programming problem on the computer
and simulate (execute) it. In this section, Python will be used to develop the simulation model. The
Python library, which can be used to simulate the linear programming model on the computer is the
linprog module, which you must be imported from scipy.optimize. The linprog module was
designed to obtain the optimal solution for a minimization linear programming program, however,
in order to use it to obtain the optimal solution for a maximization linear programming problem,
the signs in the objective functions has to change from positive to negative and from negative to
positive.
Similarly, linprog handles only the less or equal sign in the constraints, however, in order to use it
for greater than or equal constraints, the signs in the constraints have to change from negative to
positive and from positive to negative. Since Python is ideal for representing data in form of list,
the linprog module uses the same list structure in Python to represent both the objective and
constraints models. The following examples, illustrates how Python can be used to develop the
simulation model for the Industrial Chemist linear programming problem.
Recall that the following linear programming model was developed for the Industrial Chemist linear
programming problem:

Maximize Z = 5x + 4y
Subject to: 6x + 4y <= 24
x + 2y <= 6
y <= 2
-x + y <= 1
x >= 0
y >= 0
Since this is a maximization problem, in order to use linprog to write the simulation model, the
objective function has to be changed from maximization to minimization, by changing the signs as
follows:

Minimize Z = -5x - 4y
Subject to: 6x + 4y <= 24

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 8


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

x + 2y <= 6
y <= 2
-x + y <= 1
x >= 0
y >= 0
This can be represented in Python as follows, after importing linprog:

from scipy.optimize import linprog

obj = [-5,-4]
lhs = [[6,4],[1,2],[0,1],[-1,1]]
rhs = [24,6,2,1]
bnd = [(0,float('inf')), (0,float('inf'))]
optimization = linprog(c=obj,A_ub=lhs, b_ub=rhs, bounds = bnd, method = 'simplex')
optimization

After the simulation, the output of the simulation model is shown below as:

fun: -21.0
message: 'Optimization terminated successfully.'
nit: 2
slack: array([0. , 0. , 0.5, 2.5])
status: 0
success: True
x: array([3. , 1.5])

From the output of the simulation model, it shows that the values of x and y are 3 and 1,5, respecti
vely.

Exercise/Assignment
The following table shows the hourly output of two plants A and B that produce two products X
and Y with the cost per hour.

Product X Product Y Cost/Hour


Plant A 140 70 70
Plant B 70 110 60
Total Required Production 5600 4200
How many hours must plants A and B, respectively operate, to produce the required output for the
minimum cost?

Hint:
1. Model the problem as a linear programming problem.
2. Use simplex method to manually determine the optimal hour that plants A and B will operate
in order to minimize cost.
3. Write a Python simulation model for the linear programming problem.
4. Compare the Python simulation with the manual computation.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 9


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

2.1.4 Graphical Solution to the Linear Programming Problem


The solution of linear programming problem obtained either through the simulation model or
manual computation of the simplex method can be verified using the graphical method. The
graphical solution to the linear programming problem is a visual solution to the linear programming
problem, which involves the use of graph paper to plot the various constraints of the linear
programming problem. After plotting the various constraints, the points in the region formed as a
result of the plotting will be substituted into the objective function, the point that maximizes or
minimizes the objective function as the case may be will the optimal solution to the linear
programming problem. Since the graph paper is two dimensional in nature, therefore, this approach
is ideal when the basic variables of the linear programming model are only two, i.e. x and y.
Illustrating with the Industrial Chemist linear programming problem, when you plot each of the
constraints in a graph paper, you obtain the following, as shown below.

2 E D

1 F Solution Space

A B

4 6

After the plotting of the various constraints, the following points, A, B, C, D, E and F will be
substituted in the objective function, the point that maximizes the objective function will be the
optimal solution to the linear programming model. At point A, which is (0, 0), the value of the

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 10


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

objective function is z = 5*0 + 4*0 = 0. At point B, which is (4, 0), the value of the objective
function is z = 5*4 + 4*0 = 20. At point C, which is (3, 1.5), the value of the objective function is
z = 5*3 + 4*1.5 = 21. At point D, which is (2.3, 2), the value of the objective function is z = 5*2.3
+ 4*2 = 19.5. At point E, which is (1.6, 2), the value of the objective function is z = 5*1.6 + 4*2 =
16. At point F, which is (0, 1), the value of the objective function is 5*0 + 4*1 = 4, Comparing all
the values of the objective function z, it is very clear that the point that maximizes the objection
function is point C, which is (3, 1.5), with the value of z = 21. Therefore, the optimal solution the
linear programming model is x = 3 and y = 1.5, this is the same as the solution obtained using the
simulation model and the manual computation of the simplex method.

2.2 Transportation Model


The transportation model is another optimization/operation research model, which aim at
determining the optimal quantities of an item to be moved or distributed from different sources to
different destinations, which will minimize the total cost of moving the items from the various
sources to the various destinations. The transportation model is represented as a table, where the
rows of the table are the various sources, and the columns of the table are the various destinations.
In each cell of the table is the unit cost of moving the item from the corresponding source to the
corresponding destination. The total amount of items from all the sources must be equal to the total
amount of items to all the destinations, when this happens; you say that the transportation model is
balanced. If a transportation model is not balanced, then it must be balanced before it can be called
a transportation model. Balancing an unbalanced transportation model requires introducing a
dummy supply or a dummy source, with zero cost per unit in each of the cells of the dummy supply
or dummy source. The table below shows a transportation model with four sources and three
destinations.

Destination 1 Destination 2 Destination 3 Total

Source 1 C11 X11 C12 X12 C13 X13 3

X
j =1
1j

Source 2 C21 X21 C22 X22 C23 X23 3

X
j =1
2j

Source 3 C31 X31 C32 X32 C33 X33 3

X
j =1
3j

Source 4 C41 X41 C42 X42 C43 X43 3

X
j =1
4j

Total 4 4 4 4 3

 X i1
i =1
 X i2
i =1
 X i3
i =1
 X
i =1 j =1
ij

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 11


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

The process of representing a real life situation in a transportation model is called modelling or
formulating a transportation problem.

2.2.1 Solution to the Transportation Model


Solving a transportation model is to determine the values of Xij, which will minimize the total cost
of moving the items from the various sources to the various destinations. There are different
numerical methods/algorithms, which can be used to solve the transportation problem, however,
the one that will be presented here is the Vogel Approximation Method, VAM. Furthermore, the
transportation model can be reduced as a linear programming model, and the simulation model for
the linear programming problem can be used to solve the transformed transportation model. The
transportation model described in the last section can be reduced as a linear programming model as
follows:
4 3
Minimize z =  Cij X ij
i =1 j =1

Subject to:
3
X11 + X12 + X13 = X
j =1
1j

3
X21 + X22 + X23 = X
j =1
2j

3
X31 + X32 + X33 = X
j =1
3j

3
X41 + X42 + X43 = X
j =1
4j

4
X11 + X21 + X31 + X41 = X i =1
i1

4
X12 + X22 + X32 + X42 = X i =1
i2

4
X13 + X23 + X33 + X43 = X i =1
i3

4
X14 + X24 + X34 + X44 = X i =1
i4

2.2.2 Vogel Approximation Numerical Method


The Vogel approximation numerical method can be stated in form of algorithm, as outlined below:

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 12


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

1. Determine the starting basic variable or starting feasible solution.


2. Use simplex optimality test to determine the entering variable. If it satisfies the optimality
test, stop, otherwise proceed to step 3.
3. Use simplex feasibility test to determine the leaving variable.
4. Continue from step 2.

Elaborating further on each of the steps above:


1. Determine the starting basic variable or starting feasible solution.
Though different numerical methods can be used to do this, but using the Vogel approximation
method, the following applies:
1.1 For each row and each column, determine the row and column penalty. The row or
column penalty is the difference between the smallest unit cost and the next smallest
unit cost in that row or column.
1.2 Determine the row or column with the highest row or column penalty.
1.3 In the row or column with the highest row or column penalty, allocate as much as
possible to the cell with the smallest unit cost, with the aim of satisfying both the
supply and demand for that row and column.
1.4 Cross out the row or column that has been satisfied as a result of such allocation.
Only one row or one column can be crossed out at any time.
1.5 Repeat steps 1.2, 1.3 and 1.4 until all the rows and columns have been allocated and
crossed. However, if one row or column with non zero demand or supply remains,
allocate as much as possible to the cell of that row or column with the least cost, but
the row or column with a zero supply or demand remains, stop. On the other hand,
if more than one row or column with zero supply or demand remains, determine the
basic variable based on the cell with least cost.
The starting basic variables are the variables that the cells have been allocated, while those
that the cells have not been allocated are the starting non basic variables. The following
example will be used to illustrate the use of the above steps.

Example:
MG Auto has three plants in Los Angeles, Detroit and New Orleans and two major distribution
centres in Denver and Miami. The capacities of the three plants during the next quarter are 1000,
1500 and 1200 cars. The quarterly demand at the two distribution centres are 2300 and 1400. The
mileage chart between the plants and the distribution centres are given in the table below.

Denver Miami
Los Angeles 1000 2690
Detroit 1250 1350
New Orleans 1275 850

The trucking company in charge of transporting the cars charges 8 cent per mile per car. Model the
problem as a transportation model and linear programming model. Use the use the Vogel
approximation numerical method to determine the starting basic variables and the starting non basic
variables.

In order to model the problem as a transportation model, you will need to determine the cost to
transport one car from each of the sources to each of the destinations. From the description, the cost
per car per mile is 8 cent, and the table above has provided the mileage chart, therefore, you can
easily compute the cost per car from each of the sources to each of the destinations. Similarly, the

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 13


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

description of the system has provided you with information with respect to the total demand and
total supply, therefore, the transportation model follows below:

Denver Miami Total Supply


Los Angeles $80.00 $215.20 1000

X11 X12
Detroit $100.00 $108.00 1500

X21 X22
New Orleans $102.00 $68.00 1200
X32
X31
Total Demand 2300 1400 3700

The transportation model can be transformed into linear programming model as follows:

Minimize Z = 80X12 + 215.20X12 + 100X21 + 108X22 + 102X31 + 68X32


Subject to: 80X12 + 215.20X12 = 1000
100X21 + 108X22 = 1500
102X31 + 68X32 = 1200
80X12 + 100X21 + 102X31 = 2300
215.20X12 + 108X22 + 68X32 = 1400

Next, you determine the starting basic variables using the table below:

Denver Miami Supply Row Penalty1 Row Penalty1


Los Angeles $80.00 $215.20 1000 135

X
1000
Detroit $100.00 $108.00 1500 8 8

1300 200
New Orleans $102.00 $68.00 1200 34 34

X
1200
Demand 2300 1400 3700
Column Penalty 20 40
2 40
From the above table, the starting basic variables are the variables for the allocated cells, which
are: X11, X21, X22 and X32, while the starting non basic variables are the variables for the cells that
were not allocated, which are: X12, X31

2. Use simplex optimality test to determine the entering variable. If it satisfies the
optimality test, stop, otherwise proceed to step 3.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 14


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

2.1 Determine the multipliers for each row and column. The multipliers, U i and Vj must
satisfy the condition, Ui+Vj = Cij, for each of the basic variable, Xij. You begin by
assigning 0 to the Ui multiplier.
2.2 Determine the value of the expression, Ui+Vj-Cij, for each non basic variable.
2.3 For all the values calculated in 2.2, determine the value with the highest positive value,
that will become the entering variable. If non exists, then the simplex optimality test has
been satisfied, which means that there is no entering variable, as a result, there will be
no leaving variable. However, suppose there is an entering variable, then you proceed
to the next step, step 3.

Illustrating with the MG Auto example, you will have the following table, which is shown below:

Denver, Miami Supply Row Penalty1 Row Penalty1


V1= 80 V2= 88
Los Angeles $80.00 $215.20 1000 135

U1 = 0 X -127.2
1000
Detroit $100.00 $108.00 1500 8 8

U2 = 20
1300 200
New Orleans $102.00 $68.00 1200 34 34

U3 = -20 X -42
1200
Demand 2300 1400 3700
Column Penalty 20 40
2 40

From the above table, none of the computer value, , Ui+Vj-Cij has a positive value, therefore, the
simplex optimality test has been satisfied. The optimal values of the basic variables are: X11 = 1000,
X21 = 1300, X22 = 200, X32 = 1200, while the values for the non basic variables are: X 12 = 0 and
X31 = 0
However, suppose the optimality test does not hold at the end of the steps in step 2, you proceed to
the steps in step 3.

3. Use simplex feasibility optimality test to determine the leaving.


3.1 Beginning at the entering variable cell, form a close loop by moving in a horizontal
and vertical direction, each corner or vertex of the close loop must be one of the
basic variable cells.
3.2 Beginning at the entering variable cell, add and subtract alpha alternatively, in each
corner or vertex of the close loop.
3.3 Determine the maximum value of alpha, which will make one of the basic variables
zero. The maximum value of alpha, which makes the basic variable zero will become
the leaving variable.
3.4 Adjust the value of Xij for the basic variables, where alpha was added and
subtracted.
3.5 Repeat from step 2.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 15


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

Exercise:
Three refineries, with daily capacities of 6, 5 and 8 million gallons, respectively, supply three
distribution areas with daily demands of 4, 8 and 7 million gallons, respectively. Gasoline is
transported to the three distribution areas through a network of pipeline. The transportation cost is
10 cents/1000 gallons per pipeline mile. The table that follows gives the mileage between the
refineries and the distribution areas. Refinery 1 is not connected to distribution area 3.
1. Model the problem as a transportation model.
2. Remodel the transportation model as a linear programming model.
3. Use VOGEL approximation numerical method to determine the optimal amount of crude
oil to be distributed from the various refineries to the three distribution areas.

Distribution Area 1 Distribution Area 2 Distribution Area 3


Plant 1 120 180 -
Plant 2 300 100 80
Plant 3 200 250 120

2.3 Network Model


This is another important optimization/operation research model, which is represented as an
interconnection of various nodes, called network diagram. A network model is an interconnection
of various nodes; it is used to solve different problems, which includes: shortest route problem,
minimal spanning tree problem, etc. Each of these network problems has its own numerical
method/algorithm, which is used to solve the problem. The network problem, which you will learn
how to solve, is the shortest route problem. The shortest route problem is a network problem, which
determines the shortest route from a node to another node. There are different numerical
methods/algorithm that solves the shortest route problem, but you will learn the Dijkstra’s shortest
route algorithm as a numerical method that solves the shortest route problem.

2.3.1 Dijkstra’s Shortest Route Algorithm


This numerical method/algorithm that solves the shortest route problem was developed by E. W.
Dijkstra. The Algorithm uses labeling convention to determine the shortest route between a node
and any other node in a network. There are different versions of this algorithm, but the most efficient
of these versions of Dijkstra’s Algorithm will be considered. This version of Dijkstra’s Algorithm
uses two sets, temporary and permanent set. Each of these sets consists of nodes that are labeled as
follows [a,b]c, where, a, is the distance between the source node and the node that you are labeling,
and, b, is the sequence or intermediate node that will be used to reach the node you are labeling,
from the source node. The algorithm commences by initializing the temporary set to empty, but the
permanent set will be initialized to this labeled node [0,-]p, the letter p represents the pivot node,
which is initialized to the source node. The algorithm performs an iteration by determining the
neighbors of the pivot node, all the neighbors of the pivot node will be labeled temporarily,
afterwards one of the labeled node of the temporary set will be moved to the permanent set, and
that will become the pivot node, the process continues until the temporary set becomes empty. The
algorithm can be formalized as follows:

1. Initialize the temporary set Ct to empty


2. Initialize the permanent set, Cp to [0, -]p, where p is the current pivot, the source node.
3. Determine all the neighbors of the pivot node, which are not in the permanent
set.
4. Label all the neighbors that you have determined in 3, as follows [a, b]c, where
a is the addition of the distance from the source node to the current pivot node

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 16


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

and the distance from the pivot node to the node c that you are labeling; b, is
the current pivot node, and c is the current node that you are labeling.
5. Insert each of the nodes that you have labeled in 4 into the temporary set, Ct. If
the node is already in the temporary set, determine the one with the minimum
value of, a, the one with the minimum value of, a, will be in the temporary set
while the other will be ignored.
6. Pick a node in the temporarily labeled set that has the minimum value of, a,
7 Insert the label into the permanent set and remove it from the temporary set.
This node will become the current pivot node.
8. Repeat steps 3, 4, 5, 6 and 7 until the set of temporarily labeled set becomes
empty
The set of permanently labeled set can be used to determine the shortest route between the source
node and any other node in the network. The following example will illustrate further.

Example:
Consider the network diagram below, use the Dijkstra’s Algorithm to determine the shortest route
from node 1 to node 8.

4
3 6

1 2
2 3

8
1 2 5 6 5
1

7
1 2 3 6

5 8 7
2 4

Solution:
Using the Dijkstra’s Algorithm, we proceed as follows:
1. Initialize Ct = Empty
2 Intialize Cp = { [0, -]1 }
3 Neighbors of the pivot node, 1 are nodes 2, 3
4 Label the neighbors as follows: [1,1]2, [2,1]3
5 Insert the labeled nodes into temporary set; Ct = { [1,1]2, [2,1]3 }
6 Pick pivot node with minimum distance from temporary set as [1,1]2
7 Insert it into Cp and delete it from Ct; Cp = { [0,-]1, [[1,1]2 } and Ct =
{ [2,1]3 }
Second Iteration:
3. Neighbors of the pivot node, 2 are 3, 4, 5
4. Label the neighbors as follows: [2,2]3, [6,2]4, [3,2]5
5 Insert labeled nodes into temporary set; Ct = { [2,1]3, [6,2]4, [3,2]5 }. Since
node 3 is already in the temporary set with the same distance as the new
label as the one we intend to insert, we pick one arbitrarily and ignore the

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 17


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

other.
6 New pivot is node 3
7 Cp = { [0,-]1, [[1,1]2, [2,1]3 } and Ct = { [6,2]4, [3,2]5 }
Third Iteration:
3 Neighbors of the pivot node 3 are 4, 5 and 6
4 Label the neighbors as follows [4,3]4, [3,3]5, [6,3]6
5. Insert labeled nodes into temporary set; Ct = { [4,3]4, [3,2]5, [6,3]6 }
6 New pivot is node 5
7 Cp = { [0,-]1, [[1,1]2, [2,1]3, [3,2]5 } and Ct = { [4,3]4, [6,3]6 }
Fourth Iteration:
3 Neighbors of the pivot node 5 are 6, 7
4 Label the neighbors as follows [6,5]6, [10,5]7
5 Insert labeled nodes into temporary set, Ct = {[4,3]4, [6,3]6, [10,5]7 }
6 New pivot is node 4
7 Cp = { [0,-]1, [[1,1]2, [2,1]3, [3,2]5, [4,3]4,} and Ct = { [6,3]6, [10,5]7 }
Fifth Iteration:
3 Neighbors of the pivot node 4 are 6, 7
4 Label the neighbors as follows [[10,4]6, [12,4]7
5 Insert labeled nodes into temporary set, Ct = { [6,3]6, [10,5]7 }
6 New pivot node is node 6
7 Cp = { [0,-]1, [[1,1]2, [2,1]3, [3,2]5, [4,3]4, [6,3]6 } and Ct = { [10,5]7 }
Sixth Iteration
3 Neighbors of pivot node 6 are 7, 8
4 Label the neighbors as follows [11,6]7, [8,6]8
5 Insert labeled nodes into temporary set, Ct = { [10,5]7 }
6 New pivot node is node 8
7 Cp = { [0,-]1, [[1,1]2, [2,1]3, [3,2]5, [4,3]4, [6,3]6, [8,6]8 } and Ct = { [10,5]7 }
Seventh Iteration:
3. Neighbors of node 8 is empty
4 Nothing to label
5 Nothing to insert into temporary set, Ct
6 New pivot node is node 7
7 Cp = { [0,-]1, [[1,1]2, [2,1]3, [3,2]5, [4,3]4, [6,3]6, [8,6]8, [10,5]7 } and Ct = { }

Since Ct is now empty, the iteration stops, and we have the set Cp, the set of permanent set as: Cp
= { [0,-]1, [[1,1]2, [2,1]3, [3,2]5, [4,3]4, [6,3]6, [8,6]8, [10,5]7 }
From this set we can easily read the shortest route from node 1 and any other node in the network:
From node 1 to 8, you go through node 6
From node 1 to 6, you go through node 3
From node 1 to 3, you go through node 1
This shortest route can be represented, using this diagram below.

3
6

1 8

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 18


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

Example:
Consider the network diagram below, and use the Dijkstra’s algorithm to determine the shortest
route from node 1 to node 4.

2
2 5

5 3 1
5

1 4
1 1
6
7
3 3

4
3 7
12

Solution:
Using the Dijkstra’s Algorithm, we proceed as follows:
1. Initialize Ct = Empty
2 Intialize Cp = { [0, -]1 }
3 Neighbors of the pivot node, 1 are nodes 2, 3
4 Label the neighbors as follows: [5,1]2, [3,1]3
5 Insert the labeled nodes into temporary set; Ct = { [5,1]2, [3,1]3 }
6 Pick pivot node with minimum distance from temporary set as [3,1]3
7 Insert it into Cp and delete it from Ct; Cp = { [0,-]1, [[3,1]3 } and Ct =
{ [5,1]2 }
Second Iteration:
3. Neighbors of the pivot node, 3 are 2, 4, and 7
4. Label the neighbors as follows: [4,3]2, [10,3]4, [15,3]7
5 Insert labeled nodes into temporary set; Ct = { [4,3]2, [10,3]4, [15,3]7 }.
6 New pivot is node 2
7 Cp = { [0,-]1, [[3,1]3, [4,3]2 } and Ct = { [10,3]4, [15,3]7 }
Third Iteration:
3. Neighbors of the pivot node, 2 are 4, and 5
4. Label the neighbors as follows: [6,2]5, [9,2]4
5 Insert labeled nodes into temporary set; Ct = { [9,2]4, [6,2]5, [15,3]7 }.
6 New pivot is node 5
7 Cp = { [0,-]1, [[3,1]3, [4,3]2, [6,2]5 } and Ct = { [9,2]4, [15,3]7 }
Fourth Iteration:
3. Neighbors of the pivot node, 5 are 4, and 6
4. Label the neighbors as follows: [9,5]4, [7,5]6

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 19


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

5 Insert labeled nodes into temporary set; Ct = { [9,2]4, [7,5]6, [15,3]7 }.


6 New pivot is node 6
7 Cp = { [0,-]1, [[3,1]3, [4,3]2, [6,2]5, [7,5]6 } and Ct = { [9,2]4, [15,3]7 }
Fifth Iteration:
3. Neighbors of the pivot node, 6 is node 4
4. Label the neighbors as follows: [8,6]4
5 Insert labeled nodes into temporary set; Ct = { [8,6]4, [15,3]7 }.
6 New pivot is node 4
7 Cp = { [0,-]1, [[3,1]3, [4,3]2, [6,2]5, [7,5]6, [8,6]4 } and Ct = {[15,3]7 }
Sixth Iteration:
3. Neighbors of the pivot node, 4 is node 7
4. Label the neighbors as follows: [10,4]7
5 Insert labeled nodes into temporary set; Ct = { [10,4]7 }.
6 New pivot is node 7
7 Cp = { [0,-]1, [[3,1]3, [4,3]2, [6,2]5, [7,5]6, [8,6]4, [10,4]7 } and Ct = {}
The iteration stops since the set of temporary label is empty. The shortest route from node 1 to
node 4 can be read as follows:
From node 1 to node 4, go through node 6
From node 1 to node 6, go through node 5
From node 1 to node 5, go through node 2
From node 1 to node 2 go through node 3
From node 1 to node 3, go through node 1
Therefore, we move as follows: 1 to 3 to 2 to 2 to 5 to 6, with a total distance of 8

2 5

1 4
6

Exercise
Use Dijkstra’s algorithm to determine the shortest route between node 1 and node B in this
network diagram.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 20


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

1
2 4
0
3
2 5 5

3 4

2 7

1 2 2
6

3 4
4

8
7 6

4
A
9 3
4

2.3.2 Simulation Models for Dijkstra’s Shortest Route Algorithm


Different programming language can be used to convert the Dijkstra’s shortest route algorithm into
a simulation model, which the computer can execute. Each of the available simulation model can
use different data structures, like graph, matrices etc, to represent a network on the computer.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 21


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

3. Queuing/Stochastic Models
3.0 Introduction
Queuing models are mathematical models, which can be used to describe a queuing system, i.e. a
system that has arrival of item or departure of item or both arrival and departure of items. The
queuing models that will be considered in this section are stochastic in nature, because they are
derived using the concept of probability theory. The queuing models are predictive models, rather
than optimization model because they are aim at predicting/determining a particular metric of a
queuing system, rather than optimizing the metric. In this section, the different queuing models,
which describe a particular queuing application, will be considered, and for each queuing model, it
will be simulated on the computer, with different simulation trials that will help to understand the
relationship between the variables of the queuing model. Graphical plots will also be used to
visually understand the relationship between the variables of the queuing models.

3.1 Queuing Models for Pure Birth Queuing System


The pure birth queuing system is a type of queuing system where there is only arrival of
items, without departure. One of the problems that you can solve in a pure birth queuing
system is to determine the probability that x number of items arrive in a pure birth queuing
system per unit time. This problem can be solved using a special probability density
function, called Poisson probability density function.

3.1.1 Poisson Probability Density Function


The Poisson probability density function, which helps to determine the probability that x
items arrive in a pure birth queuing system is given by the model, which is shown below:

 x e − 
 , x = 0 ,1,2,3,4,5,6,7,...
P( X = x) =  x!
0 , otherwise

The above model, which determines the probability that x items arrive in a pure birth
queuing system depends on x and  . Therefore, using this model to understand a pure birth
queuing system, the model will be simulated on the computer, at different experimental runs
of the simulation model/program, the values of x will be changing, while other variables
will remain constant, this will help to predict/determine the probability that x items arrive
at the pure birth queuing system per unit time. When the various probabilities are plotted
against x, the result of the simulation is shown below.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 22


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

P(X)
0.08

0.06

0.04

0.02

0
0 20 40 60 80 100 120
-0.02

Similarly, for different experimental runs of the simulation model/program, as the value of
 changes, while other variables remain constant, the result of the simulation, which is the
predicted probability of the number of items in the queuing system, when plotted against
the various value of  , the results of the simulation is shown in the graph below.

P(X)
0.06
0.05
0.04
0.03
0.02 P(X)

0.01
0
0 50 100 150 200
-0.01

These results show that the model for the Poisson probability density function tends to
behave like normal distribution, when the arrival rate is large.

3.2 Queuing Models for Pure Death Queuing System

The pure death queuing system is a queuing system, where there is only departure, without
arrival. One of the problems that you can solve in a pure death queuing system is to
determine the probability that x items remains in a pure death queuing system. The model
that helps you to predict/determine the probability that x number of items remains in a pure
death queuing system is called Truncated Poisson probability density function. The model
for the trucketed Poisson probability density function is given as:

 ( t ) N − x e − t
 , x = 0 ,1,2,3,4,5,6,7,...N
P( x) =  ( N − x)!
0 , otherwise

This model depends on x, N and t , its behaviour is similar to the model for Poisson
probability density function.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 23


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

3.3 Queuing Models for Single Server, Finite, Birth and Death Queuing System

In a birth and death queuing system, there is both arrival and departure. Some of the
problems that you can solve in this queuing system is to predict the following metrics: the
probability that x items are in the queuing system, i.e. the probability that the system is in
state x, the average number of items in the queuing system, the waiting time in the queuing
system, the average number of items in the queue, the waiting time in the queue, the
percentage of utilization of the server. Relevant models have been developed for each of the
above metrics of a birth and death queuing system. Each of the models will be considered.

3.3.1 Model for the Probability that x Items are in the Queuing System

The model that helps you to predict/determine the probability that x items is in a single
server, finite birth and death queuing system is given below:

 x 1−  
    , x = 0,1,2,..., N ,   1
N +1 
  1 −  
 1
P( x) =  , x = 0,1,2,3,..., N ,  = 1
 ( N + 1 )
0 , elsewhere



In the above model,  = ,  is the arrival rate,  is the departure rate and N is the

maximum number of items that the finite queuing system can accommodate. It is very clear
that the above model depends on the following variables, N,  and  . In order to understand
the system, using the model, the relationship between the probability, P(x) and each of the
variables will be considered. Any programming language, like Java, Python or C++ can be
used to write the simulation model/program for the above model. After writing the
simulation model/program, for different experimental run of the simulation model/program,
by keeping the following variables constant at N = 40,  = 10 and  = 5, while varying x,
the number of items in the finite queuing system, the various probabilities can be
estimated/predicted. When plotted against x, you obtain the graph below.

P(X)
0.6

0.5

0.4

0.3
P(X)
0.2

0.1

0
0 10 20 30 40 50

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 24


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

The result of the simulation shows that as that as the number of items in the queuing system,
x increases, the probability remains very low, close to zero, however, after it reaches the
value of 30, any further increase leads to a steady rise in the probability. The implication is
that with the constant values of N = 40,  = 10 and  = 5, the probability that 30 or more
items will be in the queuing system is very high, while the probability that less than 30 items
will be in the queuing system will be very low.
However, if the maximum number of items that can be in the queuing system remains 40,
while  = 10 and  = 5, the probability that very few items will be in the queuing system
will be very high, while the probability that many items will be in the queuing system will
be very low. This can be seen in the graph below.

P(X)
0.14
0.12
0.1
0.08
0.06 P(X)
0.04
0.02
0
0 10 20 30 40 50


This means that the value of  = , which is called utilization factor or queue intensity is

the game changer, the queuing system behaves differently when it is greater than 1, and
behaves in a different manner when it is less than 1.

Exercise:
Simulate the model by keeping the following variables constant at N = 40,  = 10, x = 15,
vary  from 2 to 100. Plot the result of the simulation, P(x) against  . Interpret the result
of the simulation.

3.3.2 Model for Average Number of Items in the Queuing System


The model that helps you to predict/determine the average number of items in a single
server, finite queuing system is given below as:

  1 − ( N + 1)  N + N ( N +1) 
   ,   1
  (1 −  )(1 −  N +1
) 

N
Ls =  ,  = 1
2



Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 25


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike


As usual, in the above model,  = ,  is the arrival rate,  is the departure rate and N is

the maximum number of items that the finite queuing system can accommodate. Therefore,
the average number of items in the queuing system depends on the following variables, N,
 and  . Simulating the model, using any software of your choice, and keeping the
following variables constant at N = 40,  = 100 and varying  between 2 and 308, plotting
the average number of items in the queuing system against departure rate, you obtain the
graph below.

Average Number of Items in the


Queuing System
45
40
35
30
25 Average Number of
20 Items in the Queuing
15 System
10
5
0
0 100 200 300 400

The interpretation of the simulation result is that as the utilization factor remains very high, the
average number of items in the queuing system remains constant, at close to 40. However, as the
utilization factor approaches 1, the average number of items in the queuing system begins to fall
sharply. Furthermore, as the utilization factor, which is the game changer begins continues to
decrease to value that is close to 0, the average number of items in the queuing system continues to
decrease to value that is close to 0.

4. Simulations of Some Mathematical Models


4.0 Introduction
Most of the common mathematical functions are represented as mathematical models. These
models need to be simulated so that their values can be predicted or determined. Some of these
fundamental functions, which need to be simulated, are: sine, cosine, euler function etc. These
functions are modelled as Taylor series, whose values are only approximations. The Taylor series
models for these functions need to be simulated on the computer.

4.1 Simulation of the Sine Function


The Sine function is represented as this Taylor series, which is stated below:

(−1)n −1 x 2 n −1
Sin ( x) = 
n =1 (2n − 1)!
The above model for the Sine function has n and x as its variables, n iterates from 1 to infinity,
therefore, the predicted value for Sin(x) depends on n. The simulation model/program for the model,
using recursive Java methods is shown below.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 26


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

import java.util.Scanner;
class simulatesine
{
public static void main(String args[])
{
Scanner myinput = new Scanner(System.in);
double val = 0.0, numb = 0.0;
System.out.print("Enter the value of x and n :");
val = myinput.nextDouble();
numb = myinput.nextDouble();
System.out.print("The Value of Sine " + " x " + "is "+ sinevalue(val,
numb));
}

static double sinevalue(double x, double n)


{
if (n == 1.0)
{
return (Math.pow(-1,n-1.0) * Math.pow(x, 2*n-1.0))/fact(2*n-1.0);
}
else
{
return ((Math.pow(-1,n-1.0) * Math.pow(x, 2*n-1.0))/fact(2*n-1.0))
+ sinevalue(x, n-1.0);
}
}

static double fact(double n)


{
if (n == 1.0)
{
return 1.0;
}
else
{
return n * fact(n-1.0);
}
}
}

For different experimental runs of the simulation model/program, keeping x constant at 10, and
iterating n from 1 to 25, the various predicted values of Sin(x=10) can be obtained from the
simulation. When the result of the simulation, Sin(x=10) is plotted against n, the graph below shows
the relationship between the predicted value, Sin(x) and n.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 27


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

Sin(X)
2000

1000

0 Sin(X)
0 5 10 15 20 25 30
-1000

-2000

The interpretation of the result of the simulation is that as the value of n iterates from 1, the value
of Sin(x=10) fluctuates by rising and falling, as the value of n continues to increase, the value of
Sin(x=10) remains stable at -0.5440, which is the actual value of Sin(10).

4.2 Simulation of the Euler Function


The euler function is another important mathematical function, which is modelled as Taylor series
as:

xn
e = x

n = 0 n!

The above model for the euler function depends on the variables, x and n, therefore, for a particular
value of x, e x depends on n. In a similar manner, the model can be simulated on the computer using
recursive Java methods, as shown below.

import java.util.Scanner;
class simulateuler
{
public static void main(String args[])
{
Scanner myinput = new Scanner(System.in);
double val = 0.0, numb = 0.0;
System.out.print("Enter the value of x and n :");
val = myinput.nextDouble();
numb = myinput.nextDouble();
System.out.print("The Euler Value for " + " x " + "is "+ eulervalue(val, numb));
}

static double eulervalue(double x, double n)


{
if (n == 0.0)
{
return 1.0;
}
else
{

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 28


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

return Math.pow(x, n)/fact(n) + eulervalue(x, n-1.0);


}
}

static double fact(double n)


{
if (n == 0.0)
{
return 1.0;
}
else
{
return n * fact(n-1.0);
}
}
}

For different experimental runs of the simulation model/program, by keeping x constant at 1, and n
iterates from 1 to 30 at interval of 1, the result of the predicted value of e when plotted against n is
shown below.

e
3

2.5

1.5
e
1

0.5

0
0 5 10 15 20 25 30 35

The interpretation of the result of the simulation is that as the value of n iterates from 1 to 30, and
x remains constant at 1, the value of e increases from 2, afterwards the value of e stabilizes at the
value of 2.718 as n becomes very large.

Exercises
For each of the following Taylor series model for the corresponding function,
1. Write the Java based simulation model/program that can be used to simulate the model
on the computer.
2. Perform different experimental runs of the simulation model, by keeping x constant at a
constant value of 10, and n iterates from the beginning to 50, plot the predicted value of
the function against n.

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 29


November 07, 2022 [COMPUTATIONAL SCIENCE AND NUMERICAL METHODS] O. E. Oguike

The Taylor series models are:



(−1)n x 2 n
A. Cos( x) = 
n =0 (2n)!

(−1)n −1 x n

B. Ln(1 + x) = 
n =1 n

Department of Computer Science/Mathematics, GOUNI, Enugu. Staff No: 00721 Page 30

You might also like