Manual for the Simplex Method Tadeusz Michałowski *, Maciej Rymanowski and Andrzej Pietrzyk Notations: xij – number (scalar); xi – vector, X - matrix 1. Introductory to the Simplex Method 1.1. Some fundamental concepts and data known from the geometry course In order to introduce the simplex concept, we start from the point (0-D), (I) segment (1-D), (II) equilateral triangle (2-D), and (III) tetrahedron (3-D) concepts, known from the elementary geometry. The 0-D, 1-D, 2-D, 3-D (and generally n-D) notations express the dimensionality of the corresponding geometrical entities (Fig.M1). A2 I A0 A3 A1 II III A2 A0 A1 A0 A1 Fig.M1. Segment, equilateral triangle and tetrahedron (tetragon) The points A0, A1, A2 are vertices of the triangle A0A1A2; the points A0, A1, A2, A3 are the vertices of the tetrahedron A0A1A2A3. A0A1 is one of the edges of the triangle; A0A1 is one of the edges of the tetrahedron; Equilateral triangle A0A1A2 is one of walls of the tetrahedron. Segment, equilateral triangle, and tetrahedron can be presented in the same scale; it means that all distances, equal to unity (chosen arbitrarily), between the (neighbouring) points Ai and Aj of a polygon are assumed, i.e. the length AiAj = 1. All angles between edges of the equilateral triangle are equal to 60o (π/3 rd). All angles between adjacent tetrahedron edges are equal 60o too, owing to the fact that all the tetrahedron walls are composed of equilateral triangles (2-D). By turns, tetrahedrons form the 3-D–walls in 4-D polygon, etc. It means that all angles between adjacent edges of a symmetrical n-D polygon are equal 60o, as well. * Corresponding author, E–mail address: [email protected] The equilateral triangle can assume different positions on the plane. A particular case is the triangle with unit edges, ‘anchored’ at the origin of co-ordinate axis, as one presented in Fig. M2. The successive vertices of the equilateral triangle can be presented in matrix form, where the rows are expressed by co-ordinates of the corresponding points Ai(i=0,1,2): X= 0 1 1/2 0 0 3 /2 A0 A1 A2 (M1) X2 A2 A0 A1 X1 Fig.M2. The equilateral triangle with unit edges and A0(0,0); A1(1,0), A2(0.5, 3 /2) The second and third rows of this matrix are identical with components of transposed vectors: A0A1 and A0A2, respectively: A0A1 = [ 1, 0] T, A0A2 = [ 1/2, T 3 /2] The tetrahedron can assume different positions in 3-D space. A particular case is the tetrahedron anchored at the origin of co-ordinate axis as one presented in Fig.M3. X3 A3 A0 A1 X1 A2 X2 Fig.M3. The tetrahedron with unit edges and A0(0, 0, 0); A1(1, 0, 0), A2(1/2, A3(1/2, 3 /6, 3 /2, 0); 6 /3) The successive vertices of the tetrahedron can be presented in matrix form: 2 X= 0 1 1/2 1/2 0 0 3 /2 0 0 0 A0 A1 A2 3 /6 6 /3 A3 (M2) The second, third and fourth rows of this matrix are identical with components of the transposed vectors: A0A1, A0A2 and A0A3, respectively: A0A1 = [ 1, 0, 0 ] T, A0A2 = [ 1/2, T 3 /2, 0 ] , A0A3 = [ 1/2, 3 /6, T 6 /3 ] 1.2. A generalised approach to the polygon concept in n-D space The segment, equilateral triangle and tetrahedron are imaginable concepts. However, application of the concepts involved with geometric figures of higher dimension (n≥4) is beyond imagination. One should be taken into account that, in the simplex optimisation, we are forced, as a rule, to consider higher number of factors influencing the optimising process. Although the figures in n-D space are beyond imagination, one can present them in projective space. In Fig.M4, any pair of points of the simplex is connected, informally, by a segment (line); the segments (sides, edges) are marked there with broken lines. Particularly, two points form the 1-D simplex in 1-D space. Adding a third point (that not lies along the segment or its extension) gives a triangle (2-D simplex) in 2-D space. Adding a fourth point in 3-D space (not coplanar with 2-D simplex plane), one obtains a tetrahedron (3-D simplex), etc. Generally, adding a successive k+1–th (k=2,3,...,n-1) point, do not lying in surface formed by k–1-D simplex, one obtains the k-D simplex. In other words, adding the successive point that not lies on (or in plane of) simplexes of lower dimension and connecting it, every time, with the remaining points, one can imagine the simplexes with larger and larger dimensions, in projective space (Fig.M4). 3 6 5 1 2 4 Fig.M4. Formation of consecutive dimensions (up to 6-D) of a simplex in projective space Let us assume that the polygon is ‘anchored’ in n-D–space in such a manner that A0 is in the origin of the co–ordinate axis and any successive point ‘enters’ the new dimension of the n-D–space, compare with Fig.M3. It means that the co–ordinates of the corresponding points of n-D polygon are as follows: 3 A0 = (0, 0, 0, ... , 0, 0); A1 = (x11, 0, 0, ... , 0, 0); A2 = (x21, x22, 0, ... , 0, 0); A3 = (x31, x32, x33, ... , 0, 0); ... ; An–1 = (xn–1,1, xn–1,2, xn–1,3, ... , xn–1,n–1, 0); An = (xn1, xn2, xn3, ... , xn,n–1, xnn). (M3) This means that xij = 0 for j > i. Note that the number of vertices exceeds, by 1, the dimension of the space; it means that the polygon in n-D space involves n+1 vertices. On the basis of the points Ai (I = 0,1,2, …, n) one can construct n vectors xi = A0Ai, originating at A0 and ending at the points Ai . One should notice that The basic components xij of the vector xi = A0Ai = [xi1, xi2, xi3,…, xii, …, xin]T , starting at the origin of co-ordinates, are identical with co-ordinates of the point Ai = (xi1, xi2, xi3,…, xij,…, xin). Then for the vectors A0Ai based on the points specified in (M3) we have: x1 = A0A1 = [ x11, 0, 0, …, 0 ] T, x2 = A0A2 = [x21, x22, 0, …, 0]T, x3 = A0A3 = [x31, x32, x33, 0, … , 0]T, … xi = A0Ai = [x31, x32, x33, … , xii,, 0, …, 0]T , … , xn = A0An = [xn1, xn2, xn3, … , xni, …, xnn]T (M4) Let us construct the matrix composed of the co-ordinates of the corresponding points in n-D space, as assumed above: 0 0 0 … 0 … 0 0 x11 0 0 … 0 … 0 0 x21 x22 0 … 0 … 0 0 x31 x32 x33 … 0 … 0 0 ………………………………………………. xi1 xi2 xi3 … xii … 0 0 ………………………………………………. xn-1,1 xn-1,2 xn-1,3 …xn-1,i …xn-1,n-1 0 xn1 xn2 xn3 … xni … xn,n-1 xnn X= A0 A1 A2 A3 … Ai … An-1 An (M5) On the basis of the above remark, the terms xij in the 2nd, 3rd, …, (n+1)th rows of the matrix X (eq. M3) are identical with components of the corresponding transposed vectors xi = A0Ai. 1.3. The simplex concept 1.3.1. Scalar product of vectors Let ek be the unit vector along k–th axis, Xk, i.e. ej=1. The ei vectors form a set of mutually orthogonal vectors in n-D space (Cartesian co-ordinate system). Scalar products: ei⋅ ej =ei⋅ej⋅cos(∠ei,ej) = 0 for j ≠ i and ei⋅ ei =ei⋅ei⋅cos(∠ei,ei) = 1 for j = i (M6) Any vector xi can be also written as follows: • in 2–D space: xi = [xi1, xi2]T or xi = e1⋅xi1 + e2⋅xi2 ; • in 3–D space: xi = [xi1, xi2, xi3]T or xi = e1⋅xi1 + e2⋅xi2 + e3⋅xi3 • (M7) (M8) in n–D space: xi = [xi1, xi2, ... , xin]T ; xi = e1⋅xi1 + e2⋅xi2 + ... + ek⋅xik + … + en⋅xin (M9) 4 Scalar product of two vectors, xi and xj, is as follows: x iT x j = (e1⋅xi1 + e2⋅xi2 + ... + ek⋅xik + … + en⋅xin)(e1⋅xj1 + e2⋅xj2 + ... + ek⋅xjk + … + en⋅xjn) = xi1⋅xj1 + xi2⋅xj2 + ... + xik⋅xjk + ... + xin⋅xjn (M10) (see eqs. M6). Particularly, for j = i x iT x i = xi12 + xi22 + ... + xik2 … + xin2 (M11) If the unit vectors xi are assumed, i.e.xi = 1, then xi12 + xi22 + ... + xik2 + … + xin2 = 1 (M12) If the unit vectors xi as ones specified in eq. M4 are applied, then from eq. M11 we have: xi12 + xi22 + ... + xii2 = 1 (for i = 1,…,n) (M13) The scalar product of vectors xi and xj can also be written as follows xi⋅xj =xi⋅xj⋅cos(∠xi,xj) (M14) where ∠xi,xj is the angle between vectors xi and xj. For the unit vectors we have:xi = xj = 1. As was stated above, the angle between vectors xi = A0Ai and xj = A0Aj of n-D simplex equals 60o, i.e. ∠xi,xj = 60o for any pair of the vectors xi and xj. Setting cos(∠xi,xj) = cos60o = ½, for the vectors spanning the simplex in n-D space and assuming xij ≥ 0, one can write: x112 = 1 (M15) x11⋅xi1 = 1/2 (for i = 1,…,n) (M16) x212 (M17) + x222 =1 x21⋅xi1 + x22⋅xi2 = 1/2 (M18) x312 (M19) + x322 + x332 =1 x31⋅xi1 + x32⋅xi2 + x33⋅xi3 = 1/2 (M20) From eq. M15 we have x11 = 1. Putting it into (M16), we get xi1 = 0.5; among others, x21 = 1/2, and then from the relation (M17) we get x22 = From (M18) we get xi2 = 3 /2 ≅ 0.866. 3 /6 (= 3 /2/3 ≅ 0.289). Then we take the relations: (M19) and (M20) and one obtains, by turns: x33 = 6 /3 ≅ 0.817, xi3 = 6 /12 (= 6 /3/4 ≅ 0.204). As we see (compare with matrices (M1), (M2)), the co–ordinates of the points in the matrix (M5) are derivable with none relevance to geometrical properties of the related geometrical figures (i.e. equilateral triangle, tetrahedron). Such a circumstance can be exploited for calculation of further xij values using, by turns, the relations: x412 + x422 + x432 + x442 = 1 (M21) x41xi1 + x42xi2 + x43xi3 + x44xi4 = 1/2 (M22) and, generally, ∑k=1i xik2 = 1 (M23) ∑k=1m (M24) xikxjk = 1/2 where m = min(i,j) One can introduce the notations: x11 = h1 = 1 = [½⋅(1+1)/1]1/2, x22 = h2 = 1/2 3 /2 = [½⋅(2+1)/2] , x33 = h3 = [½⋅(3+1)/3]1/2, ..., and xi1 = r1 = h1/(1+1), xi2 = r2 = h2/(2+1), xi3 = r3 = h3/(3+1), ... . Then the n-D simplex can be written in the form 5 X= 0 0 h1 0 r1 h 2 r1 r2 ... ... r1 r2 0 0 0 0 ... hn (M25) (for 1 ≤ j ≤ n) (M26) 0 ... 0 ... 0 ... h3 ... ... ... r3 ... where: 1/ 2 j + 1 h j = 2⋅ j 1/ 2 1 j +1 rj = j + 1 2 ⋅ j 1/ 2 1 = 2 j ( j + 1) (for j < i ≤ n) (M27) One can notice that hj (eq.M26) is the height of j-D symmetrical simplex and rj (eq.M27) is the radius of j-D sphere (for j=2 – circle, for j=3 – ‘normal’ sphere) inscribed in j-D simplex. Moreover, we have the relations: h j = rj + R j (M28) R j = j ⋅ rj (M29) where Rj is the radius of j-D sphere circumscribed on j-D simplex. R2 h2 r2 Fig.M5. Graphical presentation of r2 , h2 and R2 in 2-D space (equations M28 and M29) 1.3.2. Translation and reflection of the simplex Simplex can translate and/or rotate in space. Particularly, the simplex defined by X (eq. M25), with the centre at Ac = (r1,...,rn), can be parallely shifted to the centre Pc0 = (0,...,0) of the co–ordinate system. This way, one obtains a new matrix Xtr 6 − r1 R1 0 ... 0 0 Xtr = − r2 − r3 ... − rn−1 − r2 − r3 ... − rn−1 R2 − r3 ... − rn−1 ... ... ... ... 0 0 0 0 ... R n −1 ... 0 − rn − rn − rn ... − rn R n (M30) with Rj and rj (j = 1,...,n) as ones related in eq. M29. Reflection of particular vertices of the matrix Xtr in the centre of co–ordinate system (0,...,0) gives the simplex described by the matrix r1 − R 1 0 Xtr·(–I) = ... 0 0 X* = r2 r3 ... rn−1 r2 r3 ... rn−1 − R2 r3 ... rn−1 ... ... ... ... 0 0 ... − R n−1 0 0 ... rn rn rn ... rn − R n 0 (M31) where I = [ δ ij ] – identity matrix. The positions of the simplex presented in Fig. M6 (in 2-D space), obtained from (I) by translation (II) and mirror reflection (III) in the origin of ordinate axis, are presented by matrices: X (eq. M31 for n = 2 and Xtr = -r1 -r2 R1 -r2 0 R2 = -0.5 -0.289 0.5 -0.289 0 0.578 X* = I X2 = 0.5 0.289 -0.5 0.289 0 -0.578 II A2 A0 r 1 r2 -R1 r2 0 -R2 X2 A1 X1 III A2’ A0” X2 A1” X1 A0’ (M32) A1’ X1 A2” Fig. M6. The simplexes obtained after successive (II) translation and (III) reflection of the original simplex (I) in the center of co–ordinate axis in 2-D space; for details – see text. 2. Example of simplex planning The principle of the simplex planning is exemplified by gravimetric determination of Cd, based on the reaction of bromine with 8–hydroxyquinoline (oxine, HL). 7 Reagents and solutions • Solution of CdSO4⋅8/3H2O (m0 = 0.01272 g Cd/1g), standardised according to electrogravimetric and complexometric methods; • 8–hydroxyquinoline HL (3.00%, m/v) in ethanol; • tartaric acid (0.220 g/ml); • NaOH (2.51 mol/l); • Doubly distilled water. All reagents applied were of analytical purity grade. Analytical procedure The pipetted samples, ca. 5 ml of the standardised CdSO4 solution, weighed on analytical balance (±0.1 mg), were taken for analysis. The solution was treated with tartaric acid solution and then with NaOH solution. After dilution with water, the solution was treated with 8-hydroxyquinoline solution added dropwise from burette, with defined rate of addition. The mixture was leaved for defined time on the water-bath for re-crystallisation of the precipitate CdL2 at defined temperature, then filtered, washed with water, dried to a constant mass at 105 oC and weighed. Decision variables Z1 – re–crystallisation time [min] of the precipitated CdL2; Z2 – mass [g] of tartaric acid added in the solution; Z3 – volume [ml] of NaOH added; Z4 – volume [ml] of 8–hydroxyquinoline added; Z5 – rate [ml/min] of 8–hydroxyquinoline addition; Z6 – temperature [oC] of water bath where re–crystallisation of CdL2 occurs; Z7 – volume [ml] of the solution before precipitation. Matrix for initial simplex The number of decision variables: n = 7 equals to the number of columns in the simplex matrix X. Number of rows in the initial simplex: n+1 = 8. 0 1 0.5 0 .5 X = [xij] = 0.5 0.5 0.5 0.5 0.289 0.204 0.158 0.129 0.764 0 0.289 0.204 0.158 0.129 0.109 0.756 0 0 0 0 0 0 0 0 0.866 0 0 0 0.289 0.817 0 0 0.289 0.204 0.791 0 0.289 0.204 0.158 0.775 0 0 0 0 0 0 0 0 0 0 0 0 A0 A1 A2 A3 A4 A5 A6 A7 (M33) Criterion of optimisation The criterion of optimisation suggested is the sum of squares y(i) = 1/ Ni ⋅ N ∑ k =i 1 (mik − m0 )2 = (mi − m0 )2 + (1 − 1/ Ni ) ⋅ si2 (M34) 8 where the values: N mi = 1/ Ni ⋅ ∑ k =i 1 mik (M35) N si2 = (Ni − 1) −1 ⋅ ∑ k =i 1 (mik − mi ) 2 (M36) were calculated in the i–th simplex point Ai (eq. M33) on the basis of Ni results mik of measurements of an intensive variable m (e.g. number of grams of an analyte contained in unit mass of solution); m0 is the true value of this variable, obtained according to a reference method. The optimisation is terminated at the simplex point where si ⋅ t(α, fi ) Ni mi − m 0 < where si = (M37) si 2 , t(α, fi ) is the critical t-value for Student t-test found for fi = Ni – 1 degrees of free- dom on α = 0.95 probability level assumed. In our case we have s mi − m0 < i ⋅ 3.182 = 1.591⋅ si 4 (M38) Values of natural variables Zj (j = 1,…,7) within the initial simplex The value zij of j-th natural variable (Zj) at i-th point of the initial simplex (i = 0,…,n; j = 1,…,n) is defined by equation zij = z0 j + x ij ⋅ ∆z j (i = 0,1,...,7; j = 1,...,7) (M39) where i = 0,1,...,n enumerates successive experimental points related to the initial simplex X = [xij] represented by the matrix M33. On the basis of pre-assumed values for z0j and ∆zj, one can calculate the values zij of the natural variables Zj from Eq. M39. The value z0j is presented in row i=0 for variable Zj in j-column in Table 1. For example, the value z04 = 7.20 [ml] refers to variable Z4; the related value ∆z4 = 1.00 ml. From M37 and M34 and Table 1, for i = 3 and j = 4 we have z34 = 8.00 + 0.817⋅1.00 ≅ 8.82 ml. Table 1. The values for zij assumed in points of the initial (columns 1–7, rows 0–7) and evolving (columns 1–7, rows 8–10) simplexes. For all points, the values y(i) were obtained on the basis of Ni = 4 measurements. j i▼ 0 1 2 3 4 5 6 7 8 9 10 ∆zi ► z0j z1j z2j z3j z4j z5j z6j z7j z8j z9j z10,j 1 2 3 4 5 6 7 60 60 120 90 90 90 90 90 90 90 90 90 1.00 3.00 3.00 3.87 3.29 3.29 3.29 3.29 3.29 2.55 2.91 2.80 1.00 8.00 8.00 8.00 8.82 8.20 8.20 8.20 8.20 8.47 8.34 7.59 1.00 7.20 7.20 7.20 7.20 7.99 7.36 7.36 7.36 7.56 7.46 7.69 1.00 1.00 1.00 1.00 1.00 1.00 1.78 1.13 1.13 1.30 1.21 1.40 10 60 60 60 60 60 60 67.5 61 62.5 62 63 50 100 100 100 100 100 100 100 138 111 65 93 y(i)⋅108 1.2 0.7 3.0 1.9 0.7 1.3 0.8 2.3 1.3 1.8 0.5 9 Experiments done within the initial simplex The simplex optimisation procedure was realized in experiments performed in all points of the initial simplex (rows 0,…,7). In each point Ai (i = 0,…,7), Ni = 4 measurements were done. The list of results mik [g Cd/g] is presented in Table 2. Table 2. M table with results of measurements done within the initial simplex. The results are recalculated on Cd contents [g] in 1.0000 g of the solution; j = 0,…,7; k = 1,…,4. Ai A0 A1 A2 A3 A4 A5 A8. A7 mik 0.01260 0.01265 0.01256 0.01256 0.01265 0.01262 0.01262 0.01255 [g/g] 0.01263 0.01268 0.01252 0.01258 0.01267 0.01255 0.01268 0.01259 0.01257 0.01259 0.01249 0.01269 0.01260 0.01267 0.01261 0.01262 0.01268 0.01265 0.01267 0.01255 0.01264 0.01262 0.01264 0.01253 On the basis of the data in Table 2, the y(i) values were calculated (last column in Table 1). As results from detailed calculations done on the basis of results in Table 2, the inequality M39 has not been fulfilled within the initial simplex and then the evolution of the simplex was required. Evolution of the simplex At the first stage of the simplex evolution, a point Aw1 with the worst (w1) value, y(w1), for the object function is indicated, w1∈ < 0, n > . The point Aw1 is replaced by a new point, An+1, obtained by reflection of Aw1 in the centre (Ac1) of the remaining points of the initial simplex, i.e. in n–1-D wall not containing the point Aw1. The point Aw1 is replaced by a new point, An+1, obtained by reflection of Aw1 in the centre, Ac1(xc1), of the remaining n points of the initial simplex, i.e. in n–1-D wall not containing the point Aw1. In other words, xc1 = ( x1 ,..., xn )c1 is the middle point between xw1 and xn+1, i.e. T (xw1 + xn+1)/2 = xc1 = 1/n ⋅ ∑i≠w1 xi (M40) After adding the term (1/n)⋅xw1 to both sides of (M40), we obtain the co–ordinates of the new point An+1 xn+1 = 2/n ⋅ ∑i=0n xi – (1 + 2/n) ⋅ xw1 (M41) After measurement(s) done at the point An+1, the values y(i) are compared again within the new (evolved) simplex (containing An+1 and not containing Aw1) and the point Aw2 with the worst value, y(w2) is chosen. Then Aw2 is reflected in the centre of n–1-D wall of the new simplex (not containing w2). This way, a new point An+2 is obtained and further operations are repeated again, in cyclic manner. At q–th reflection one can write (xwq + xn+q)/2 = xcq = 1/n ⋅ ∑i≠wq(q) xi (M42) where , xcq = ( x1 ,..., xn )cq are co–ordinates of the centre of remaining (except the worst one) points of T the q–th evolving simplex. Referring to the Table 1, the worst (w=w1) result within the initial simplex was obtained at the point A2. During the simplex evolution, this point was reflected in the centre xc1 of the remaining points of the starting simplex. Referring to Table 1, we have, for example, x2c1 = (2⋅0 + 5⋅0.289)/7 = 0.2064 (0.866 + x82)/2 = 0.206 Æ x82 = – 0.454 z82 = 3.00 + (–0.454)⋅1 ≅ 2.55 10 x3c1 = (2⋅0 + 0.817 + 4⋅0.204)/7 = 0.233 (0 + x83)/2 = 0.233 Æ x83 = 0.466 z83 = 8.00 + 0.466⋅1 ≅ 8.47 At the point A8, the condition M38 has not been fulfilled as well, and further evolution of the simplex was required. The worst y(w2) value within the new simplex was stated in the point A7. Further calculations referred to the new point A9 are exemplified below: X2c2 = (2⋅0 + 4⋅0.289 + 1⋅(–0.454))/7 = 0.1004 (0.289 + x92)/2 = 0.1004 Æ x92 = –0.088, z92 = 3.00 + (–0.088)⋅1 ≅ 2.91; x3c2 = (2⋅0 + 0.817 + 3⋅0.204 + 0.467)/7 = 0.271 (0.204 + x93)/2 = 0.271 Æ x93 = 0.338 P93 = 8.00 + 0.338⋅1 ≅ 8.34 x7c2 = (6⋅0 + 0.216)/7 = 0.031 (0.756 + x97)/2 = 0.031 Æ x97 = –0.694, z97 = 100 + (–0.694)⋅50 ≅ 65; x2c3 = (2⋅0 + 3⋅0.289 + 1⋅(–0.454) + 1⋅(–0.088))/7 = 0.046 (0.289 + x10,2)/2 = 0.046 Æ x10,2 = –0.197 z10,2 = 3.00 + (–0.197)⋅1 ≅ 2.80 The inequality (M38) has not been fulfilled within the new simplex, as well. The worst result within the new simplex has been stated at the point A3. Then we calculate, among others: x3c3 = (2⋅0 + 3⋅0.204 + 0.467 + 0.338)/7 = 0.2024 (0.817 + x10,3)/2 = 0.2024 Æ x10,3 = –0.412, z93 = 8.00 + (–0.412)⋅1 ≅ 7.59. The steps ∆zj for the co–ordinates Zj (i.e. values for natural variables) at the points Ai (i=0,1,...) refereed to the initial (i=0,...,7) and evolving (i=8,9,10) simplex are specified in Table 1. Then the co– ordinates of the new points: A8, A9 and A10 for evolving simplexes were calculated with use of the coded variables xij, are specified in Table 3. 0.5 − 0.453 0.467 0.361 0.295 0.249 0.216 0.5 − 0.088 0.338 0.261 0.214 0.180 − 0.694 0.5 − 0.196 − 0.412 0.494 0.404 0.341 − 0.137 A8 A9 A 10 respectively. The optimisation procedure has been terminated at the point A10, where mean Cd-contents mi = 0.01267 and variance si2 = 0.32⋅10-8 were found on the basis of 4 measurements and then the inequality (M38) 0.01267 – 0.01272 < 0.56⋅10–4⋅1.591 = 0.89⋅10–4 was fulfilled and y(10) = (0.01267 – 0.01272)2 + (1 – 1/4)⋅0.32⋅10–8 = 0.49⋅10–8 ≅ 0.5⋅10–8 (see Table 1). It should be noticed that the y(i) (eq.M34) is not caused only by changes in Zi values; it is partly ascribed to random errors. 11 Optimal prescription On the basis of the optimization procedure, one can formulate the following prescription. The pipetted samples, ca. 5 ml of the standardised CdSO4 solution, weighed on analytical balance (±0.1 mg), were taken for analysis. The solution was treated with 2.80 g of tartaric acid and then with 7.9 ml of 2.5 mol/l NaOH solution. After dilution with water up to ca 90 ml, the solution was treated with 7.7 ml of 3% (m/v) 8-hydroxyquinoline solution (added dropwise from burette, with the rate 1.4 ml/min. The mixture was leaved for 90 min. on the water-bath for re-crystallisation of the precipitate CdL2 at temperature 63 oC, then filtered, washed with water, dried to a constant mass at 105 oC and weighed. 2. Description of computer program – an example All the calculations can be performed according to a very simple computer program written in MATLAB; such an option facilitates the optimisation procedure. The program is based on transformations done on the related tables (matrices). The results obtained according to the computer program can be compared with ones presented in the paper. The principle of the program is not confined, however, to the example considered in this paper. After minute changes, the program can be adopted to another optimisation purposes, made according to simplex method, for any number (n) of factors considered in the optimisation. If a user aims to resolve its own optimisation problem, he should follow the procedure analogous to one specified below. After taking the file simplex.m, it is inserted in the corresponding MATLAB catalogue. Double clicking opens the file in the text editor. Then the „Debug” and „Run” commands are chosen from Menu placed at the top of the screen. In order to follow the calculations, the experimental data, arranged conveniently for user’s needs, can be inserted in the commands line. Starting values, Zi0, for the variables (factors) Zi and their steps (∆Zi) are chosen arbitrarily. They are taken, at least partially, from analytical prescription (if attainable). Generally, some limitations put on temperature (possibility of phase change) and concentrations (limited solubility) should also be taken into account - both within the initial and evolving simplexes. At the start for optimisation, the number (n) of the optimising factors should be declared. On this basis, the (n+1) × n table, i.e. matrix X(n+1,n) with n columns and n+1 rows, with coded variables (xij) is formulated. For example, putting n = 7, one gets the matrix X(7,8), with 7 columns and 7+1=8 rows. The rows, numbered 1,...,8, define particular vertices (A0, A1,...,A7) of the starting simplex. The values in columns of the matrix X = [xij] with coded variables xij refer to j-th factor, assumed within the starting simplex. Then the starting values Zi0 for real variables Zi are inserted. In our case (see Table 1), in the line of commands we write, successively, the values: 60.0, 3.0, 8.0, 7.20, 1.0, 60.0, 100.0; the values introduced are separated by comma or spaced. The values for steps (∆Zi) for the corresponding variables Zi are introduced in the same sequence as the Zi0–values assumed in the preceding line. Referring to our case, in the line of commands we write: 60.0, 1.0, 1.0, 1.0, 1.0, 10.0, 50.0. Then, on the basis of eq. (24), the program calculates, in natural units, the co–ordinates for the corresponding 12 simplex points (vertices). This way, the matrix Z=[Zij] equidimenssional with the matrix X = [xij] of coded variables, is formulated. The true contents (m0, g/g) of Cd in the solution tested is inserted; we write the number 0.01272 in the command line. Next, the value for confidence level (α, %) due to Student’s t–test is assumed; we write the number 95 in the line of commands. In the program, equal number of measurements (Ni = 4) was assumed at each (i-th) simplex point; we write the number 4 in the line of commands. On the basis of the α and Ni values, the program calculates critical values t(α,f) for the Student’s t–test, t(α,f) = t(0.95, 3) = 3.182 (f = 4 – 1 = 3). In experimental part of the optimisation procedure, the measurements were performed under the conditions provided by the Table 1. In our case, 8 x 4 = 32 individual measurements of Cd–contents (mik, g/g) were done. The results of measurements, specified in Table 2 (table M), obtained in particular points of the initial simplex, are written successively and spaced, in the line of commands : 0.01260 0.01265 0.01256 0.01256 0.01265 0.01262 0.01262 0.01255 0.01263 0.01268 0.01252 0.01258 0.01267 0.01255 0.01268 0.01259 0.01257 0.01259 0.01249 0.01269 0.01260 0.01267 0.01261 0.01262 0.01268 0.01265 0.01267 0.01255 0.01264 0.01262 0.01264 0.01253 After inserting the results related to i–th point of the simplex, press ENTER and then the next line is written. Summarising, the table M (4×8) of experimental results is thus obtained. The results in each column are referred to particular measurements done at all eight points of the starting simplex. Then mean values, mmean(i), for results (m) found in particular simplex points and standard deviations ( s(i) ) are calculated and collected in the corresponding tables, denoted as mmean(1x8) and s(1x8). It enables the y(i) values ( table y(1x8) ) to be calculated in particular points of the initial simplex, compare with Table 1 (last column, rows 0 ÷ 7). The y(i) value is the criterion of quality of results obtained in i–th point of the simplex. Low y(i) values are obtained for results characterised by relatively good accuracy and good precision. In order to choose whether the condition given by inequality (M37) is fulfilled, two next tables, named as: absbias = mi – m0 ref = ( s i / N i )⋅t(α, fi) were prepared (absbias – abbr. for absolute bias, ref – abbr. for reference value). Then the corresponding elements of the tables (absbias and ref) are compared. If the element of the table absbias is lower than the corresponding element of table ref, then optimal conditions are found at this point. Referring to the optimisation procedure illustrated in Table 1, one can state that the inequality (M37) was not fulfilled at any point (i = 0,1,...,7) of the initial simplex. Then we were forced to indicate the 13 point (Aw1) characterised by greatest y(w1) (i.e. the worst) value; w1 ∈ < 0, 7 >. From detailed inspection (Table 1), we have stated that the worst result, y(3) = y(w1) = 3.0⋅10-8, occurs at i = 2, i.e. at the third simplex point (A2). In further part of the optimisation procedure, the point Aw1, referred to the vector xw1, is reflected in the centre (Ac1) of the remaining points of the starting simplex. This operation is done according to eq. 20. This way, the new point, denoted in Table 1 as A8, is obtained and the starting (‘old’) simplex is replaced by the new (evolved) simplex containing A8 and not containing A2 = Aw1. In the new (updated) matrix X, referred to the evolved simplex, the row referred to the worst result is replaced by the row referred to the point A8 and the (updated) matrix Z of natural variables is determined. The updated matrix involves the row with (coded or natural) co-ordinates of the point A8 and the program displays the information: “Optimal values for factors were not found within the scope of the initial simplex. The worst result was found in the point no. 3. Do further measurements at the following values for factors assumed at the point A8: 90.0000 2.5464 8.4666 7.5614 1.2951 62.4939 110.7990 ” where the measurements were done. The values for the parameters assumed in measurements were rounded (reasonably) to three significant numbers, i.e. 90.0 2.55 8.47 7.56 1.30 62.5 111 After 4 measurements done at the point A8, the following results were obtained: A8 m8k 0.01260 0.01255 0.01263 0.01268 This column of numbers is inserted into the table M as the column inscribed to A2 and mk2. This operation facilitates the calculation procedure and any additional activities involved with assigning the numbers designed for calculation are not needed. These values were inserted in the command line as: 0.01260 0.01255 0.01263 0.01268 On this basis, the tables: M, mmean, s, y, absbias and ref are updated; e.g. the value for y(3) ≈ 3.0⋅10-8 is updated by the new value y(8) ≈ 1.3⋅10-8. Then the absbias and ref values referred to the point A8 are compared, as previously. It was stated that the inequality (M38) was not fulfilled. This circumstance required further evolution of the simplex. For this purpose, the point A7 with the worst value y(8) ≈ 2.3⋅10-8 has been reflected in the centre xc2 of the remaining points and coordinates of the new point, A9, are found. Further activities were the same as above; they can be formulated as a loop of experimental and computational activities, considered repeatedly and alternately. After each successive step, where optimal values required from the viewpoint of relation (M38) were not obtained, the program displays the information similar to one specified above. 14 On the basis of measurements done on particular steps, the new numerical data evidenced every time in the corresponding tables (i.e. M, mmean, s, y, absbias and ref) are displayed. All the procedure is terminated at the point where the criterion of optimisation (relation M38) is reached. In our case, the inequality (M38) was attained at the point A10. As we see, the measurements at the points A9 and A10 were also required. At the point A9, the program displays the following information “Optimal values for factors were not found within the scope of the evolved simplex. The worst result was found in the point no.8. Do further measurements at the following values for factors assumed at the point A9: 90.0000 2.9116 8.3374 7.4614 1.2134 61.8036 65.2890” (see table 1, row no.9). After 4 measurements done at the point A9, the following results were obtained: A9 m9k 0.01257 0.01264 0.01260 0.01255 and written in the line of commands as : 0.01257 0.01264 0.01260 0.01255 At the point A9, the program displays the following information “Optimal values for factors were not found within the scope of the evolved simplex. The worst result was found in the point no.4. Do further measurements at the following values for factors assumed at the point A10: 90.0000 2.8039 7.5882 7.6942 1.4035 63.4101 93.1680 After 4 measurements done at the point A10, the following results were obtained: A10 m10,k 0.01261 0.01274 0.01268 0.01264 and written in the line of commands as : 0.01261 0.01274 0.01268 0.01264 At the point A10, the optimal values were reached and the program displayed the following information: ” The following optimal values were searched: Zopt = 90.0000 2.8039 7.5882 7.6942 1.4035 63.4101 93.1680” (see Table 1, row no. 10). Ultimately, the optimal conditions were found after three evolving procedures realised on the initial simplex. 15 Remarks The optimisation procedure presented above requires some comments. It may happen that the condition (M38) is fulfilled in i-th point of the starting simplex, at i < n. In this case, the optimisation procedure can be terminated at this point, without the necessity to do further measurements in the remaining points of the simplex. So the measurements done factually in the remaining points of the starting simplex provide a kind of redundant information. However, the measurements done in the remaining point tended to check out whether better results for y(i) are obtainable. 3. Printout of the computer program clear; clc; fnd=0; n=input('Give the number of factors(n): ') X=zeros(n+1,n); Z0=zeros(n+1,n); DZ=zeros(n+1,n); % Applying the formulae for hj (eq. 10) and rj (eq. 11), formulate the matrix X (eq. 8) for the n-value assumed for j=1:1:n X(j+1,j)=sqrt((j+1)/(2*j)); end for u=1:1:(n-1) for j=1:1:(n-u) X(j+u+1,j)=sqrt(1/(2*j*(j+1))); end end display(strvcat('Input the number (N) of experimental points at each (i-th) point of the simplex',... 'Equal number (Ni = N) of measurements at each (i-th) point is assumed')) Ni=input('Input the number of measurements (N) at each point of the simplex: ') display('Write: 0.01272') m0=input('Give true value: ') display('Write 95') doft=input('Give confidence level in [%]: ') doft=doft/100; alpha=1.0-doft; doft=(1-alpha/2); X; % Formulation of the matrix with starting values (Z0j, j = 1,...,n) of natural variables display('Write: 60.0, 3.0, 8.0, 7.20, 1.0, 60.0,100.0') Z0j=input('Give starting value for natural variables: ','s') Z0j=eval(strcat('[',Z0j,']')) % Formulation of the matrix with the steps DZj (j = 1,...,n) for the starting values Z0j display('Write: 60.0, 1.0, 1.0, 1.0, 1.0, 10.0, 50.0') DZj=input('Give step value for natural variables: ','s') dZj=eval(strcat('[',DZj,']')) for a=1:1:(n+1) Z0(a,:)=Z0j; DZ(a,:)=dZj; end Z0; DZ; % From matrices: X, Z0 and DZ, the components of the matrix Z (eq.18) are % calculated 16 Z=Z0 +X.*DZ for w=1:1:(n+1) display(strvcat(' Write in A0 : 0.01260 0.01263 0.01257 0.01268',... ' Write in A1 : 0.01265 0.01268 0.01259 0.01265',... ' Write in A2 : 0.01256 0.01252 0.01249 0.01267',... ' Write in A3 : 0.01256 0.01258 0.01269 0.01255',... ' Write in A4 : 0.01265 0.01267 0.01260 0.01264',... ' Write in A5 : 0.01262 0.01255 0.01267 0.01262',... ' Write in A6 : 0.01262 0.01268 0.01261 0.01264',... ' Write in A7 : 0.01255 0.01259 0.01262 0.01253')) display(strcat('Input the results of measurements at the point A',num2str(w-1),': ')) data=input('Input the results of measurements:(in line, separated by comma or spaced): ','s') data=eval(strcat('[',data,']')) data=data' M(:,w)=data end % Formulation of the matrix mmean with mean values referred to results % of measurements done in the simplex points mmean=sum(M,1)./Ni % Formulation of the matrix with standard deviations referred to results % of measurements done in the simplex points s=std(M,0,1) % Formulation of the matrix for object function (y, eq. 15) values y=(mmean-m0).^2 + (1-1/Ni).*(s.^2) % Formulation of matrices: absbias and ref ref=abs(mmean-m0) absbias=s./sqrt(Ni).*tinv(doft,Ni-1) % Check out whether the inequality (17) is fulfilled within the initial simplex for i=1:1:n+1 if ref(1,i) < absbias(1,i) display('The following optimal values were searched:') Zopt=Z(i,:); return end end % Searching the worst point (w) in the matrix y [C,I] = max(y,[],2) nbpn=num2str(I); % Mirror reflection of the worst point (w) in the centre of remaining points of current simplex % Calculation of co-ordinates of the new simplex point (eq. 20) and inserting it in the 'old' matrix X X(I,:)=(2/n).*(sum(X,1)) - X(I,:).*(1+2/n) % Calculation of co-ordinates of the new matrix Z with natural variables (eq. 18), % involving the new simplex point, put for the worst point Z(I,:)=Z0(I,:)+ X(I,:).*DZ(I,:) % Check out whether the inequality (17) is fulfilled within the new simplex for i=1:1:n+1 if ref(1,i) < absbias(1,i) display('The following optimal values were searched:') Zopt=Z(i,:); return end end % Replacing, in matrix M, the results in the worst point (w) by results of measurements obtained in the new point if fnd==0 17 display(strvcat('Optimal values for factors were not found within the scope of the initial simplex. '... ,strcat('The worst result was found in the point no.',nbpn,'.')... ,strcat('Do further measurements at the following values for factors assumed at the point A',num2str(n+1))) ); Z(I,:) end nbpn0=n+2; while fnd==0 Z=Z0 +X.*DZ; display(strcat('Input the results of measurements at the point A',num2str(nbpn0-1),': ')) display(strvcat(' Write in A8 : 0.01260 0.01255 0.01263 0.01268',... ' Write in A9 : 0.01257 0.01264 0.01260 0.01255',... ' Write in A10 : 0.01261 0.01274 0.01268 0.01264')) newdata=input('Input the results of measurements:(in line, separated by comma or spaced):','s') newdata=eval(strcat('[',newdata,']')) newdata=newdata' M(:,I)=newdata % Updating the matrix mmean with mean values... mmean=sum(M,1)./Ni % ... and the matrix s of standard deviations s=std(M,0,1) % Calculation of the matrix y for n+1 points of the new (evolved) simplex y=(mmean-m0).^2 + (1-1/Ni).*(s.^2) % Updating the matrices: ref and absbias (compare with relation 17) ref=abs(mmean-m0) absbias=(s./sqrt(Ni)).*tinv(doft,Ni-1) % Check out whether a simplex point exists where the inequality (17) is fulfilled for i=1:1:n+1 if ref(1,i) < absbias(1,i) Zopt=Z(i,:); fnd=1; end end % Searching the worst point (with maximal y-value) in the current simplex [C,I] = max(y,[],2) nbpn=num2str(I); nbpn0s=num2str(nbpn0); % The mirror reflection of the worst point in the current simplex % Calculation of co-ordinates of the new simplex point and putting them % for co-ordinates of the worst point (formation of the updated matrix X) X(I,:)=(2/n).*(sum(X,1)) - X(I,:).*(1+2/n) % Calculation of updated matrix Z (see eq. 18), with the new point put for the worst point Z(I,:)=Z0(I,:)+ X(I,:).*DZ(I,:) if fnd==0 display(strvcat('Optimal values for factors were not found within the scope of the evolved simplex. '... ,strcat('The worst result was found in the point no.',nbpn,'.')... ,strcat('Do further measurements at the following values for factors assumed at the point A',nbpn0s)) ); Z(I,:) end nbpn0=nbpn0+1; end display('The following optimal values were searched :') Zopt 18
© Copyright 2026 Paperzz