Solver Functions

1. Overview

GS-Calc provides several solver functions for linear programming, binary/integer programming, quadratic programming, Monte‑Carlo minimization, simplex minimization, and root finding. These functions allow you to solve constrained optimization problems directly inside worksheets.

All solver functions return either:

All solver functions use non‑negative variables. If a problem requires negative variables, each must be replaced by a pair of non‑negative variables.


2. LProg — Linear Programming

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

2.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.2 Arguments

2.3 Behavior

2.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}


3. LProgBin — Binary Linear Programming

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

3.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).

3.2 Arguments

3.3 Behavior

3.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}


4. LProgInt — Integer Linear Programming

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

4.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.

4.2 Arguments

4.3 Behavior

4.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}


5. QProg — Quadratic Programming

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

5.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.

5.2 Arguments

5.3 Behavior

5.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}


6. minMC — Monte‑Carlo Minimization

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

6.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().

6.2 Arguments

6.3 Notes and Errors

6.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}

6.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}


7. minSimplex — Downhill Simplex Minimization

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

7.1 Purpose

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

7.2 Arguments

7.3 Errors

7.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

7.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


8. root — One‑Dimensional Root Finding

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

8.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.

8.2 Arguments

8.3 Errors

8.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