Calculator
Formula used
For each linear constraint with coefficients aj and variables xj, the left-hand side is:
LHS = Σ (aj · xj)
Feasibility is checked using a tolerance ε to handle rounding near boundaries.
How to use this calculator
- Set the number of variables and constraints, then submit once.
- Name each variable and enter a numerical value for evaluation.
- For each constraint, type coefficients, pick ≤ / ≥ / =, and enter the RHS.
- Press submit to see slack or surplus and feasibility above the form.
- Use the export buttons to download the latest results as CSV or PDF.
Example data table
Sample inputs (variables x1=3, x2=2, x3=1) and outputs are shown below.
| Constraint | LHS | Relation | RHS | LHS value | Slack/Surplus | Feasible |
|---|---|---|---|---|---|---|
| C1 | 2 x1 + 1 x2 + 0 x3 | ≤ | 10 | 8 | 2 | Yes |
| C2 | 1 x1 − 3 x2 + 2 x3 | ≥ | 0 | -1 | -1 | No |
| C3 | 1 x1 + 1 x2 + 1 x3 | = | 6 | 6 | 0 | Yes |
Input structure and constraint capacity
The calculator supports up to 6 decision variables and 10 constraints per run. That is 60 coefficient fields plus 10 relations and 10 right‑hand sides, enabling classroom linear programs and business cases. Variable names are editable, so models can reflect production, demand, time, or cost labels.
Slack and surplus measurement
For a ≤ constraint, slack is computed as s = RHS − LHS. For a ≥ constraint, surplus is computed as e = LHS − RHS. When a constraint is feasible, the corresponding slack or surplus is non‑negative; negative values indicate violation at the entered variable values. Units follow the RHS units, so a capacity in hours yields slack in hours.
Feasibility with numerical tolerance
Feasibility is evaluated using ε, so borderline cases are handled consistently. The check uses LHS ≤ RHS + ε for ≤ constraints, LHS ≥ RHS − ε for ≥ constraints, and |LHS − RHS| ≤ ε for equalities. A default ε = 1e‑9 suits most decimal inputs, while larger ε values can stabilize comparisons when data is rounded to few decimals.
Equation conversion for standard form
Each inequality is transformed into an equality by adding a slack variable for ≤ constraints or subtracting a surplus variable for ≥ constraints. For example, 2x1 + x2 ≤ 10 becomes 2x1 + x2 + s1 = 10, with s1 ≥ 0. This conversion is the first step before simplex‑style methods and helps interpret constraints as “used capacity + remaining capacity = limit”.
Result table and export readiness
After submission, the result table summarizes each constraint: expression, relation, RHS, evaluated LHS, slack/surplus, and feasibility. The same dataset is stored for export, so the CSV and PDF downloads match the on‑screen results exactly. CSV fits into spreadsheets for further analysis, while the PDF provides an audit trail for assignments, reports, or documentation.
Graph interpretation for quick diagnostics
The Plotly bar chart visualizes slack or surplus per constraint, making tight constraints and violations obvious. Bars near zero indicate binding constraints, large positive bars indicate unused capacity, and negative bars highlight infeasible constraints at the chosen variable values. Use the chart alongside the table to prioritize which constraints need coefficient review or which variable values must change.
FAQs
What is a slack variable in linear constraints?
A slack variable converts a ≤ inequality into an equality by adding non‑negative unused capacity. It equals RHS minus the evaluated LHS, so it measures how much room remains before the limit becomes binding.
What is the difference between slack and surplus?
Slack applies to ≤ constraints and is computed as RHS − LHS. Surplus applies to ≥ constraints and is computed as LHS − RHS. Both should be non‑negative for feasibility at the chosen variable values.
Why does the calculator use a tolerance ε?
Floating‑point inputs can create tiny rounding errors near boundaries. ε provides a consistent decision rule, treating values within ε of the boundary as equal, which prevents misleading feasible/infeasible flips when numbers are rounded.
Can I use this tool to solve an optimization problem?
This tool evaluates constraints for the values you enter and shows slack or surplus. It does not compute an optimal solution. Use it to validate candidate solutions, inspect binding constraints, and prepare standard‑form equations.
How should I interpret negative slack or surplus?
A negative value indicates a violation. For a ≤ constraint, negative slack means LHS exceeds RHS. For a ≥ constraint, negative surplus means LHS is below RHS. Adjust variable values or coefficients to restore feasibility.
Do the CSV and PDF exports match the on‑screen results?
Yes. The export buttons use the latest submitted results stored on the server. The downloaded files include the same constraint labels, expressions, relations, RHS, evaluated LHS, slack or surplus, and feasibility status.