GS-Calc Help > Calculation Functions > Optimization/Solver Functions

Function Index

LProg LProgBin LProgInt QProg minMC minSimplex root

Optimization/Solver Functions


LProg(A, s, b, c, vector, [epsilon], [BigM])

1. Purpose

Finds one or more solutions for a linear programming problem with m constraints of the form:

(1) Σj=1..n(x[j]·a[i,j]) ≤ b[i]
(2) Σj=1..n(x[j]·a[i,j]) = b[i]
(3) Σj=1..n(x[j]·a[i,j]) ≥ b[i]

and a maximized objective function:

Σj=1..n(x[j]·c[j])

2. Arguments

3. Behavior

4. Example

Initial constraints:

2·x1 + x2 + 2·x3 ≤ 20
3·x1 − x2 + x3 = 10

Objective function:

3·x1 + x2 − x3 → max

Formula:

=LProg({2, 1, 1; 1, 1, 3}, {1; 0}, {5; 10}, {4; 2; 2}, 1,,)

returns {1; 0; 3}


LProgBin(A, s, b, c, bin, vector, [epsilon], [BigM])

1. Purpose

Finds one or more solutions for a linear programming problem with constraints of the same form as LProg, where some or all variables x[i] are required to be binary (0 or 1).

2. Arguments

3. Behavior

4. Example

Initial constraints:

2.5·x1 + 1.5·x2 + x3 ≤ 15
x1 + 1.5·x2 + 3·x3 = 10

Objective function:

x1 + x2 + 2·x3 → max

Formula:

=LProgBin({2.5, 1.5, 1; 1, 1.5, 3}, {1; 0}, {15; 10}, {1; 1; 2}, {1; 0; 1}, 1,,)

returns {1; 4; 1}



LProgInt(A, s, b, c, int, vector, [epsilon], [BigM])

1. Purpose

Finds one or more solutions for a linear programming problem with constraints of the same form as LProg, where some or all variables x[i] are required to be integers.

2. Arguments

3. Behavior

4. Example

Initial constraints:

2.5·x1 + 1.5·x2 + x3 ≤ 15
x1 + 1.5·x2 + 3·x3 = 10

Objective function:

x1 + x2 + 2·x3 → max

Formula:

=LProgInt({2.5, 1.5, 1; 1, 1.5, 3}, {1; 0}, {15; 10}, {1; 1; 2}, {1; 0; 1}, 1,,)

returns {4; 0; 2}



QProg(A, s, b, p, C, vector, [epsilon])

1. Purpose

Finds one or more solutions for a quadratic programming problem with m constraints:

(1) Σj=1..n(x[j]·a[i,j]) ≤ b[i]
(2) Σj=1..n(x[j]·a[i,j]) = b[i]
(3) Σj=1..n(x[j]·a[i,j]) ≥ b[i]

and a maximized objective function:

pᵀ·x − xᵀ·C·x

where p is an n‑element column vector and C is a positive‑definite n×n matrix representing a quadratic form.

2. Arguments

3. Behavior

4. Example

Constraints:

x1 + 2·x2 ≤ 10
x1 + x2 ≤ 9
x1 ≥ 0, x2 ≥ 0

Objective function:

f(x1, x2) = 10·x1 + 25·x2 − 10·x1² − x2² − 4·x1·x2 → max

Data:

A = {1, 2; 1, 1}
s = {1; 1}
b = {10; 9}
p = {10; 25}
C = {10, 2; 2, 1}

Formula:

=QProg({1, 2; 1, 1}, {1; 1}, {10; 9}, {10; 25}, {10, 2; 2, 1}, 1,)

returns {0; 5}


minMC(f(x), x, v, from, to, points)

1. Purpose

Performs n‑dimensional minimization of a given function using the Monte‑Carlo method. The function generates a number of random points in n dimensions and returns the point for which f(x) is smallest. This method can be used to obtain an initial vector for minSimplex().

2. Arguments

3. Notes and Errors

4. Example (RC notation)

The r2c4 cell contains:
=exp((r3c4-1)*r3c4 + (r4c3-2)*r4c3 + (r5c3-3)*r5c3) - 10*exp(-((r3c4-3)*(r3c4-3) + (r4c4-3)*(r4c4-3) + (r5c4-3)*(r5c4-3)))

The r3c4:r5c4 range contains any numbers.
=minMC(r2c4, r3c4:r5c4, {1;1;1}, -5, 5, 10000) returns {0.675, 2.725, 2.960}

5. Example (A1 notation)

The D2 cell contains:
=exp((D3-1)*D3 + (C4-2)*C4 + (C5-3)*C5) - 10*exp(-((D3-3)*(D3-3) + (D4-3)*(D4-3) + (D5-3)*(D5-3)))

The D3:D5 range contains any numbers.
=minMC(D2, D3:D5, {1; 1; 1}, -5, 5, 10000) returns {0.554969, 2.661842, 3.279377}



minSimplex(f(x), x, v, [start], [epsilon], [max_steps], result)

1. Purpose

Performs n‑dimensional minimization of a given function using the downhill simplex method.

2. Arguments

3. Errors

4. Example (RC notation)

The r2c4 cell contains:
=exp((r3c4-1)*r3c4 + (r4c3-2)*r4c3 + (r5c3-3)*r5c3) - 10*exp(-((r3c4-3)*(r3c4-3) + (r4c4-3)*(r4c4-3) + (r5c4-3)*(r5c4-3)))

The r3c4:r5c4 range contains:
{0.5; 3; 2}

=minSimplex(r2c4, r3c4:r5c4, {1;1;1},,,,1) returns {0.59358762694774; 3.00000004102304; 2.9999999389697}
=minSimplex(r2c4, r3c4:r5c4, {1;1;1},,,,2) returns 0.75509
=minSimplex(r2c4, r3c4:r5c4, {1;1;1},,,,3) returns 275

5. Example (A1 notation)

The D2 cell contains:
=exp((D3-1)*D3 + (C4-2)*C4 + (C5-3)*C5) - 10*exp(-((D3-3)*(D3-3) + (D4-3)*(D4-3) + (D5-3)*(D5-3)))

The D3:D5 range contains:
{0.5; 3; 2}

=minSimplex(D2, D3:D5, {1;1;1},,,,1) returns {0.59358762694774; 3.00000004102304; 2.9999999389697}
=minSimplex(D2, D3:D5, {1;1;1},,,,2) returns 0.75509
=minSimplex(D2, D3:D5, {1;1;1},,,,3) returns 275



root(f(x), x, x0, x1, [epsilon])

1. Purpose

Finds a root of a one‑dimensional equation f(x) = 0 using a modified secant method. The method is convergent if f(x) is continuous on [x0, x1] and f(x0)·f(x1) < 0.

2. Arguments

3. Errors

4. Example

The r2c3 cell contains:
=r3c3*r3c3 + sin(r3c3) - 5

=root(r2c3, r3c3, 0, 3, ) returns 2.02521163744482
=root(r2c3, r3c3, -3, 0, ) returns -2.38467666014657