23
Chapter 3 Some Mathematical Algorithms and Problems in GAMS Technology In this chapter we present some mathematical problems expressed and solved using the GAMS technology. The applications include computing the inverse of a matrix, the determinant, and the rank of real or complex matrices, solving algebraic systems of real or complex linear equations, determining the polygon of maximal area among all polygons with a given number of sides and diameter less than or equal to one, computing the smallest circle that contains a given number of points, maximizing the area of a hexagon in which the diameter must be less than or equal to one, solving minimal surface problems, and generating prime numbers. The purpose of this chapter is to illustrate the power of the GAMS language with an emphasis on the use of loops, while and dynamic definition of sets. 3.1 Calculating the Inverse of a Matrix (Invmat) For inverse calculation of a given matrix A we can use the following two methods. The first method is to find the inverse column by column. We can solve Ax i ¼ e i ; where x i represents the i -th column of the inverse A 1 , and e i is the i -th column of the identity matrix. Therefore, the columns ½x 1 ; ... ; x n form the matrix A 1 . The second method consists of solving the linear system AX ¼ I; from which we obtain the inverse X ¼ A 1 . The GAMS model that implements the foregoing procedures are given in Fig. 3.1. N. Andrei, Nonlinear Optimization Applications Using the GAMS Technology, Springer Optimization and Its Applications 81, DOI 10.1007/978-1-4614-6797-7_3, © Springer Science+Business Media New York 2013 25

[Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

  • Upload
    neculai

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Chapter 3

Some Mathematical Algorithms

and Problems in GAMS Technology

In this chapter we present some mathematical problems expressed and solved using

the GAMS technology. The applications include computing the inverse of a matrix,

the determinant, and the rank of real or complex matrices, solving algebraic

systems of real or complex linear equations, determining the polygon of maximal

area among all polygons with a given number of sides and diameter less than or

equal to one, computing the smallest circle that contains a given number of points,

maximizing the area of a hexagon in which the diameter must be less than or equal

to one, solving minimal surface problems, and generating prime numbers. The

purpose of this chapter is to illustrate the power of the GAMS language with an

emphasis on the use of loops, while and dynamic definition of sets.

3.1 Calculating the Inverse of a Matrix (Invmat)

For inverse calculation of a given matrix A we can use the following two methods.

The first method is to find the inverse column by column. We can solve

Axi ¼ ei;

where xi represents the i-th column of the inverseA�1, and ei is the i-th column of the

identity matrix. Therefore, the columns ½x1; . . . ; xn� form the matrixA�1. The secondmethod consists of solving the linear system

AX ¼ I;

from which we obtain the inverse X ¼ A�1.

The GAMS model that implements the foregoing procedures are given in

Fig. 3.1.

N. Andrei, Nonlinear Optimization Applications Using the GAMS Technology,Springer Optimization and Its Applications 81, DOI 10.1007/978-1-4614-6797-7_3,

© Springer Science+Business Media New York 2013

25

Page 2: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.1 GAMS expression of application 3.1 (Invmat)

26 3 Some Mathematical Problems in GAMS Technology

Page 3: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

For the preceding example the matrix A and its inverse A�1 are as follows:

A ¼

1 2 3 4 4

1 3 4 3 1

1 4 1 2 6

2 4 1 1 1

3 1 5 2 7

26666664

37777775;

A�1 ¼

0:355 �0:477 �0:413 0:558 0:140

�0:225 0:209 0:202 0:023 �0:078

�0:335 0:407 0:068 �0:233 0:109

0:568 �0:244 �0:207 0:140 �0:132

�0:043 �0:047 0:159 �0:116 0:054

26666664

37777775

3.2 Inverse, Determinant and Rank of a Matrix

Determination (InvDetRang)

To compute all these elements, we use the Gaussian elimination method with

complete pivoting. This model in GAMS illustrates the use of loops and the

dynamic definition of sets in elementary transformations of Gaussian elimination

with complete pivoting (Kalvelagen 2002).

Fig. 3.1 (continued)

3.2 Inverse, Determinant and Rank of a Matrix Determination (InvDetRang) 27

Page 4: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.2 GAMS expression of application 3.2 (InvDetRang)

28 3 Some Mathematical Problems in GAMS Technology

Page 5: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

The GAMS expression of Gaussian elimination with full pivoting is shown in

Fig. 3.2.

For the example considered in Fig. 3.2 matrix A and its inverse A�1 , the

determinant and rank are as follows:

A ¼1 2 3

1 3 4

1 4 1

24

35; A�1 ¼

3:250 �2:500 0:250�0:750 0:500 0:250�0:250 0:500 �0:250

24

35; detðAÞ ¼ 4; rankðAÞ ¼ 3:

3.3 Solving Systems of Complex Linear Equations

(SysComp)

Numbers of the form z ¼ aþ ib, i is defined by the expression i2 ¼ �1, are called

complex numbers. Here a is the real part of z and b is its imaginary part. A system of

complex linear algebraic equations inCn can be very easily mapped into a problem

in R2n . The system of linear equations with complex coefficients and variables

Ax ¼ b can be expanded into the following system with real coefficients

and variables:

reðAÞ �imðAÞimðAÞ reðAÞ� �

reðzÞimðzÞ� �

¼ reðbÞimðbÞ� �

:

Fig. 3.2 (continued)

3.3 Solving Systems of Complex Linear Equations (SysComp) 29

Page 6: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Let us consider the following system of linear equations:

ð30þ 10iÞ ð20� 15iÞ15 ð8� 4iÞ

� �z1z2

� �¼ 14þ 5i

11� 7i

� �:

The implementation of this method is illustrated in the following simple GAMS

program (Fig. 3.3):

The solution of the preceding system is z1 ¼ 1:534� i0:258 and z2 ¼ �1:045�i0:914.

Fig. 3.3 GAMS expression of application 3.3 (SysComp)

30 3 Some Mathematical Problems in GAMS Technology

Page 7: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

3.4 Inverting a Complex Matrix and Solving the

Corresponding System with a Given Right-Hand-Side

Term (Invcmat)

For this problem we can use the same approaches described in the preceding

applications. Given the complex matrix A and the complex right- hand-side b we

search A�1 such that:

reðAÞ �imðAÞimðAÞ reðAÞ� �

reðA�1ÞimðA�1Þ� �

¼ I0

� �:

Explicitly, the preceding linear system can be written as:

Xk

reðaikÞreða�1kj Þ � imðaikÞimða�1

kj Þ ¼ eij;

Xk

imðaikÞreða�1kj Þ � reðaikÞimða�1

kj Þ ¼ 0:

Let us consider the following system of complex linear algebraic equations:

30þ 3i �20þ 50i 5þ 20i�20þ 7i 90� 666i �40þ 500i10þ 9i �40þ 500i 90� 500i

24

35 z1

z2z3

24

35 ¼

20þ 30i2þ 70i30� 10i

24

35:

The GAMS expression of this application is given in Fig. 3.4.

The inverse matrix and the solution of the system are as follows:

Inverse matrix. Real part:0.0311568 0.0093074 0.00945370.0027950 0.0033877 0.00378550.0028816 0.0036671 0.0043257

Inverse matrix. Imaginary part:-0.0099062 -0.0070129 -0.0086778-0.0007877 0.0037839 0.0033141-0.0018842 0.0030824 0.0044930

Solution. Real part:1.6266705 -0.0318598 0.0804233

Solution. Imaginary part:1.0192053 0.3743724 0.4031597

3.4 Inverting a Complex Matrix and Solving the Corresponding System. . . 31

Page 8: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.4 GAMS expression of application 3.4 (Invcmat)

32 3 Some Mathematical Problems in GAMS Technology

Page 9: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

3.5 Among All Polygons with nv Sides and Diameter d � 1;Finding the One of Maximal Area (Polygon)

The problem is described in Dolan et al. (2004, p. 3) and Graham (1975) [see also

Andrei 2001, p. 328; 2003, p. 359]. If ðri; θiÞ are the coordinates of the polygon’s

vertices, then the mathematical expression of this problem is

max1

2

Xnv�1

i¼1

riþ1ri sinðθiþ1 � θiÞ !

subject to

r2i þ r2j � 2rirj cosðθi � θjÞ � 1; 1 � i < nv; i < j � nv;

θi � θiþ1; 1 � i < nv;

θi 2 ½0; π�; ri � 0; 1 � i � nv:

Fig. 3.4 (continued)

3.5 Among All Polygons with nv Sides and Diameter. . . 33

Page 10: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.5 GAMS expression of application 3.5 (Polygon)

34 3 Some Mathematical Problems in GAMS Technology

Page 11: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

The problem is interesting since it has n2v nonlinear, nonconvex inequality

constraints. Observe that if nv ! 1, then the maximal area converges to the area

of a unit-circle equal to π=4 ffi 0:7854. This problem has many local minima. For

example, for nv ¼ 4 a square with sides of length 1=ffiffiffi2

pand an equilateral triangle

with another vertex added at distance 1 from a fixed vertex are both global solutions

with optimal value f ¼ 1=2. Indeed, the number of local minima is at least Oðnv!Þ.Therefore, general solvers are usually expected to find only local solutions.

The GAMS representation of this application is given in Fig. 3.5.

For different values of nv the performances of algorithms CONOPT, KNITRO

and MINOS are presented in the following tables (Tables 3.1, 3.2, and 3.3).

Figure 3.6 presents a polygon of maximal area, given by SNOPT, with nv ¼ 10

and nv ¼ 20, respectively.

Table 3.1 nv ¼ 100, n ¼ 201

(variables), m ¼ 5; 050(constraints)

#iter Time vfo

CONOPT 442 20.738 0.78481114

KNITRO 49 21.490 0.71973268

MINOS 48 13.238 0.6749814

Table 3.2 nv ¼ 200, n ¼ 401

(variables), m ¼ 20; 100(constraints)

#iter Time vfo

CONOPT 1,066 180.730 0.78515482

KNITRO 39 264.530 0.72685233

MINOS 217 236.164 0.7322066

Table 3.3 nv ¼ 300, n ¼ 601

(variables), m ¼ 45; 150(constraints)

#iter Time vfo

CONOPT 2,319 762.438 0.78529080

KNITRO 49 3,476.609 0.72686364

MINOS 282 763.039 0.68840451

Fig. 3.6 Maximal-area polygon with nv ¼ 10 and nv ¼ 20

3.5 Among All Polygons with nv Sides and Diameter. . . 35

Page 12: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

3.6 Finding the Smallest Circle That Contains a Given

Number of Points ðxi; yiÞ (Circle)

This problem is taken from Kalvelagen (2001). Consider a circle of radius r and

center ða; bÞ, which contains all np given points ðxi; yiÞ. The mathematical model of

this application is

mina;b;r

r

subject to:

ðxi � aÞ2 þ ðyi � bÞ2 � r2; i ¼ 1; . . . ; np; r � 0:

To solve this application, i.e., to find a; b, and r, we need to specify an initial

point. The initial point has a crucial value for getting good results. Some details

on starting point can be found in Kalvelagen (2001). Therefore, we consider

xmin¼ min1�i�np

xi , xmax ¼ max1�i�np

xi , ymin ¼ min1�i�np

yi and ymax ¼ max1�i�np

yi , with which

the following estimation of the initial point is computed:

a ¼ ðxmin þ xmaxÞ=2; b ¼ ðymin þ ymaxÞ=2; r ¼ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiða� xminÞ2 þ ðb� yminÞ2

q:

The GAMS expression of this application is given in Fig. 3.7.

The following tables present the performances of CNOPT, KNITRO and

MINOS (Tables 3.4, 3.5, and 3.6).

This application illustrates the importance of choosing the starting points in

an optimization problem. If we had chosen a different initial point, then all

the algorithms would face difficulties in solving this application. For example, for

np ¼ 100, KNITRO cannot solve the problem.

3.7 Maximizing the Area of a Hexagon in Which

the Diameter Must Be Less Than or Equal

to One (Hexagon)

The problem is to determine the coordinates of the vertices ðxi; yiÞ of a hexagon of

maximal area in which the distance between any two vertices is less than or equal to

one (Graham 1975; Pearson 1968; Himmelblau 1972). To simplify the problem,

one vertex is fixed at the origin and another is on the x-axis. If the first vertex is

selected as the origin of the coordinate system and the second one is on the x-axis,then x1, y1, and y2 do not appear in the problem. The GAMS representation of this

application is given in Fig. 3.8.

36 3 Some Mathematical Problems in GAMS Technology

Page 13: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.7 GAMS expression of application 3.6 (Circle)

Table 3.4 np ¼ 100, n ¼ 3

(variables), m ¼ 100

(constraints)

#iter Time vfo

CONOPT 6 0.023 5.42768655

KNITRO 52 0.280 5.42768752

MINOS 8 0.078 5.427687

3.7 Maximizing the Area of a Hexagon in Which the Diameter. . . 37

Page 14: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

The solution of this problem is as follows:

xi yi

0 0

0.349132 0

0.596652 0.501189

0.174566 0.984645

�0.387993 0.675755

�0.327853 0.120021

Figure 3.9 illustrates a hexagon of maximal area with diameter less than or equal

to one.

The performances of CONOPT, KNITRO, MINOS and SNOPT are given in

Table 3.7.

3.8 Minimal-/Surface Problem (Surface)

Consider a continuously differentiable function f : R2 ! R with domf ¼ C. Thesurface area of its graph is given by-

A ¼ðC

ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi1þ rf ðxÞk k22

qdx;

which, as we can see, is a convex functional of f . The minimal surface problem is to

find the function f that minimizesA subject to some constraints such as given values

of f on the boundary of C.This problem is approximated by discretizing the function f . Let C ¼ ½0; 1��

½0; 1�, and let fij denote the value of f at the point (i=K; j=K), for i; j ¼ 0; . . . ;K .

Table 3.5 np ¼ 500,

n ¼ 3 (variables),

m ¼ 500 (constraints)

#iter Time vfo

CONOPT 7 0.023 6.01176788

KNITRO 49 0.250 6.01176889

MINOS 7 0.133 6.011768

Table 3.6 np ¼ 1; 000,n ¼ 3 (variables),

m ¼ 1,000 (constraints)

#iter Time vfo

CONOPT 7 0.117 6.21321892

KNITRO 52 0.791 6.21321955

MINOS 6 0.055 6.213219

38 3 Some Mathematical Problems in GAMS Technology

Page 15: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.8 GAMS expression of application 3.7 (Hexagon)

3.8 Minimal-/Surface Problem (Surface) 39

Page 16: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

An approximate expression of the gradient of f at the point x ¼ ði=K; j=KÞ can be

computed using forward differences:

rf ðxÞ � 1

K2

fiþ1; j � fi;jfi;jþ1 � fi;j

� �:

Introducing now this into the expression for the area of the graph, and

approximating the integral as a sum, we obtain an approximation for the area of

the graph as:

A � Adiscret ¼ 1

K2

XK�1

i;j¼0

ð fiþ1; j � fi; jÞ=Kð fi; jþ1 � fi; jÞ=K� �����

����2

:

Observe that Adiscret is a convex function of fi; j.To determine the function f that minimizes Adiscret, a large variety of constraints

on fi; j can be imposed. In this application we consider the problem of finding the

Fig. 3.9 Solution of application 3.7

Table 3.7 n ¼ 18

(variables), m ¼ 21

(constraints)

#iter Time vfo

CONOPT 16 0.050 0.6749814

KNITRO 7 0.130 0.6749813

MINOS 8 0.090 0.6749814

SNOPT 25 0.131 0.6749814

40 3 Some Mathematical Problems in GAMS Technology

Page 17: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

minimal-area surface with fixed boundary values on the left and right edges of the

square ½0; 1� � ½0; 1�:

minAdiscret

subject to:

f0; j ¼ lj; j ¼ 0; . . . ;K;

fK; j ¼ rj; j ¼ 0; . . . ;K;

where f i;j, i; j ¼ 0; . . . ;K, are the variables, and lj and rj are given boundary values onthe left and right sides of the square ½0; 1� � ½0; 1�.

Considering lj ¼ rj ¼ 1, j ¼ 0; . . . ;K, the GAMS representation of this applica-

tion is presented in Fig. 3.10.

Figure 3.11 represents the solution of the problem.

The performance of the algorithms is given in Table 3.8.

3.9 Finding the Surface with Minimal Area That Lies

Above an Obstacle with Given Boundary Conditions

(Minsurf)

This is the problem of a Plateau, which is to determine a surface of minimal area

with a given closed curve in R3 as boundary. The problem was formulated by

Lagrange in 1760, which for the class of surfaces of the form z ¼ zðx; yÞ is reducedto the solution of the Euler Lagrange equation for minimal surfaces.

Assume that the surface can be represented in a nonparametric formv : R2 ! R;which satisfies the constraint v � vL for a given obstacle vL: Therefore, the solutionof the obstacle problem is of the form

min f ðvÞ : v 2 Kf g;

where f : K ! R is

f ðvÞ ¼ðD

1þ rvðxÞk k2� �1=2

dx

and the convex set is defined as:

K ¼ v 2 H1ðDÞ : vðxÞ ¼ vDðxÞ; x 2 @D; vðxÞ � vLðxÞ; x 2 D�

;

3.9 Finding the Surface with Minimal Area That Lies Above an Obstacle. . . 41

Page 18: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

and H1ðDÞ is the space of functions with gradients in L2ðDÞ; the function

vD :@D ! R defines the boundary data and vL : D ! R is the obstacle. We assume

that vL � vD on the boundary @D of D.A finite-element approximation to this problem is obtained by triangulating the

domainD and minimizing f over the space of piecewise linear functions with values

Fig. 3.10 GAMS expression of application 3.8 (Surface)

42 3 Some Mathematical Problems in GAMS Technology

Page 19: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

vi; j at the vertices of triangulation. Consider D ¼ ½0; 1� � ½0; 1� and use a triangula-

tion with nx and ny internal grid points in the coordinate directions. The starting

guess is the function 1� ð2x� 1Þ2 evaluated at the grid points. In this application

we consider the following boundary data

vD ¼ 1� ð2x� 1Þ2; y ¼ 0; 10; ð0; 1Þ:

The obstacle is defined as:

vL ¼ 1; x� 0:5j j � 0:25; y� 0:5j j � 0:250; otherwise:

The GAMS representation of this application is given in Fig. 3.12.

Considering different values for nx and ny the performances of CONOPT,

KNITRO, and MINOS are presented in the below following (Tables 3.9, 3.10,

3.11, and 3.12).

Figure 3.13 shows the solution of this application.

Fig. 3.11 Minimal surface

Table 3.8 n ¼ 441

(variables), m ¼ 0

(constraints)

#iter Time vfo

CONOPT 27 0.110 4.4113295

KNITRO 5 0.170 4.4113330

MINOS 800 1.061 4.411330

SNOPT 13 0.110 4.411341

3.9 Finding the Surface with Minimal Area That Lies Above an Obstacle. . . 43

Page 20: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Fig. 3.12 GAMS expression of application 3.9 (Minsurf)

44 3 Some Mathematical Problems in GAMS Technology

Page 21: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

Table 3.9 nx ¼ 40, ny ¼ 40,

n ¼ 1; 682 (variables),

m ¼ 1 (constraints)

#iter Time vfo

CONOPT 14 5.148 2.487506264

KNITRO 640 75.919 2.487573608

MINOS 1,300 19.055 2.487506

Fig. 3.12 (continued)

Table 3.12 nx ¼ 70, ny ¼ 70,

n ¼ 5; 041 (variables),

m ¼ 1 (constraints)

#iter Time vfo

CONOPT 31 0.484 2.4987446

KNITRO 14 1.046 2.4987446

MINOS 4,360 137.406 2.4987446

SNOPT 166 1.825 2.515118

Table 3.10 nx ¼ 50, ny ¼ 50,

n ¼ 2; 602 (variables),

m ¼ 1 (constraints)

#iter Time vfo

CONOPT 23 15.434 2.505616501

KNITRO 995 250.920 2.505724225

MINOS 2,100 63.148 2.505617

Table 3.11 nx ¼ 60, ny ¼ 60,

n ¼ 3; 722 (variables),

m ¼ 1 (constraints)

#iter Time vfo

CONOPT 27 1.180 2.485698315

KNITRO 604 296.506 2.48583837

MINOS 3,262 197.906 2.485698

3.9 Finding the Surface with Minimal Area That Lies Above an Obstacle. . . 45

Page 22: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

3.10 Prime Number Generation (Prime)

A prime number is a natural number greater than one that has no divisors other than

one and itself. The fundamental theorem of arithmetic establishes the central role of

prime numbers and says that any integer greater than one can be expressed as a

product of prime numbers that is unique up to ordering. The GAMS representation

of a prime number generator is given in Fig. 3.14.

The first 100 prime numbers generated by the preceding GAMS program are as

follows:

1 3.000, 2 5.000, 3 7.000, 4 11.000, 5 13.000

6 17.000, 7 19.000, 8 23.000, 9 29.000, 10 31.000

11 37.000, 12 41.000, 13 43.000, 14 47.000, 15 53.000

16 59.000, 17 61.000, 18 67.000, 19 71.000, 20 73.000

21 79.000, 22 83.000, 23 89.000, 24 97.000, 25 101.000

26 103.000, 27 107.000, 28 109.000, 29 113.000, 30 127.000

31 131.000, 32 137.000, 33 139.000, 34 149.000, 35 151.000

36 157.000, 37 163.000, 38 167.000, 39 173.000, 40 179.000

41 181.000, 42 191.000, 43 193.000, 44 197.000, 45 199.000

46 211.000, 47 223.000, 48 227.000, 49 229.000, 50 233.000

51 239.000, 52 241.000, 53 251.000, 54 257.000, 55 263.000

56 269.000, 57 271.000, 58 277.000, 59 281.000, 60 283.000

61 293.000, 62 307.000, 63 311.000, 64 313.000, 65 317.000

66 331.000, 67 337.000, 68 347.000, 69 349.000, 70 353.000

Fig. 3.13 Solution of application 3.9, nx ¼ 40, ny ¼ 40

46 3 Some Mathematical Problems in GAMS Technology

Page 23: [Springer Optimization and Its Applications] Nonlinear Optimization Applications Using the GAMS Technology Volume 81 || Some Mathematical Algorithms and Problems in GAMS Technology

71 359.000, 72 367.000, 73 373.000, 74 379.000, 75 383.000

76 389.000, 77 397.000, 78 401.000, 79 409.000, 80 419.000

81 421.000, 82 431.000, 83 433.000, 84 439.000, 85 443.000

86 449.000, 87 457.000, 88 461.000, 89 463.000, 90 467.000

91 479.000, 92 487.000, 93 491.000, 94 499.000, 95 503.000

96 509.000, 97 521.000, 98 523.000, 99 541.000, 100 547.000

Fig. 3.14 GAMS expression of application 3.10 (Prime)

3.10 Prime Number Generation (Prime) 47