Engineering/Mathematics/Systems of Linear Equations
Linear Algebra in Practice: The Trail Mix Blending Problem
A production manager allocating three raw ingredients across three product recipes faces a system of three linear equations, and the whole of introductory linear algebra is visible in how that system behaves. A small change to the recipes converts a single forced answer into a one-parameter family of choices, and the commercial decision moves from arithmetic to optimisation.
- Foundation level
- Stream: foundations
- Reading time 15 min
- Ref KVS-ENG-MATH-0002
- Taxonomy
- Engineering / Mathematics
- Problem class
- Blending / mass balance with capacity constraints
- Unknowns
- Production quantity of each of three products
- Equations
- One conservation equation per raw ingredient
- Outcome A
- Unique solution — no managerial freedom
- Outcome B
- One-parameter family — freedom, then optimisation
Overview
A food-packaging plant produces three grades of trail mix — bulk, standard and fancy — from three raw ingredients: raisins, peanuts and chocolate pieces. Each grade has a fixed recipe expressed per fifteen-kilogram batch, and the plant can receive and store a fixed quantity of each raw ingredient each morning. The production manager decides only how many kilograms of each grade to make. Everything else — recipes, storage capacity, ingredient costs, selling prices — is data.
Requiring that the day's deliveries be consumed exactly produces one equation per ingredient. Each equation is linear in the three production quantities, because the amount of an ingredient consumed is directly proportional to the amount of each product made. Three ingredients give three equations in three unknowns, and the entire operational question collapses into the solution set of that system.
The instructive part is what happens when the recipes change. With the original recipes the system has exactly one solution: there is precisely one production schedule that exhausts the day's raw materials, and the manager has no discretion at all. After the recipes are adjusted so that every grade is one-third peanuts, the same three equations admit an infinite family of solutions parameterised by a single quantity. The manager now has genuine freedom, bounded only by the physical requirement that no production quantity be negative.
That transition is the practical content of the subject. A unique solution means the constraints have used up all available freedom; an infinite solution set means degrees of freedom remain, and those degrees of freedom are the decision space over which cost, profit or any other objective can be optimised. Recognising which case applies, and quantifying how much freedom remains, is precisely what row reduction of the coefficient matrix delivers.
Definition
Blending Balance Equation
For a set of products indexed by with recipe coefficient giving the mass of ingredient per unit of product , and a supply of ingredient to be consumed exactly, the balance equation is , where is the quantity of product made. There is one such equation per ingredient, and each is linear in the production quantities.
Feasible Production Schedule
A vector of production quantities that satisfies every balance equation and the non-negativity requirement for every product. The balance equations define a flat set; the non-negativity requirements cut that flat set down to a bounded segment, region or polytope. Only points in the intersection correspond to schedules that can actually be run.
Degrees of Freedom of a Schedule
The number of independent quantities that may be chosen arbitrarily once every balance equation has been imposed. Zero degrees of freedom means a single forced schedule; one degree of freedom means a family parameterised by a single quantity, which becomes the variable of a subsequent optimisation.
Concepts
Why the balance equations are linear
Producing kilograms of bulk mix consumes batches, each containing a fixed mass of each ingredient, so the raisin consumption is — a constant times an unknown. Nothing in the process makes consumption depend on the square of the quantity produced, or on the product of two production quantities. Total consumption of an ingredient is the sum of the separate contributions of each grade. Proportionality plus additivity is exactly the definition of linearity, and it is why blending problems are the canonical first application of the subject.
The original recipes force a unique schedule
With recipes of , and kilograms of raisins, peanuts and chocolate per fifteen-kilogram batch, and daily supplies of , and kilograms, the three balance equations have the single solution , , kilograms. The manager's job is arithmetic, not judgement: any deviation leaves an ingredient either short or unconsumed. Verification is immediate — raisin consumption is , and the peanut and chocolate balances close identically.
A recipe change creates a degree of freedom
Standardising every grade at one-third peanuts changes the recipes to , and . The supplies are unchanged, but the three equations are no longer independent: the peanut equation now reduces to , which is implied by the total mass available. The system retains only two independent constraints on three unknowns, so exactly one degree of freedom survives. Taking as the free quantity gives and , and substituting these back reproduces , and identically, with every coefficient of cancelling.
Non-negativity converts an infinite set into a finite choice
Algebraically the family is infinite, extending to arbitrarily large and arbitrarily negative . Physically only part of it exists. Requiring forces ; requiring forces . The feasible interval is , and restricting to whole kilograms leaves distinct schedules, every one of which consumes the day's deliveries exactly. The linear algebra supplies the family; the inequalities supply the boundary.
The objective is linear too, so the optimum lies at an endpoint
Daily profit is the sum over grades of quantity times margin. Substituting the parameterised quantities gives , a straight line in the single free quantity. A linear objective over an interval attains its extremes at the endpoints, so no search is required: the negative slope sends the optimum to , giving , and a daily profit of 2{,}805\ available under the original recipes, where no choice existed at all. This endpoint principle is the germ of linear programming.
Price changes rotate the objective, not the feasible set
When competitive pressure cuts the standard-mix price from 5.50\ per kilogram, the balance equations are untouched and the feasible interval is unchanged. Only the objective changes, to . The slope has reversed sign, so the optimum jumps to the opposite endpoint , giving , and a profit of 2{,}664.60$. The commercial reading is sharp: the price cut drives the plant out of the standard-mix market entirely, and the optimal response is a corner-to-corner jump rather than a gradual adjustment.
From plant floor to production decision
Equations
Ingredient balance system, original recipes
EQ-TMX-01One equation per raw ingredient: raisins, peanuts and chocolate. The fractional coefficients convert kilograms of finished product into batches and then into ingredient mass.
Unique schedule under the original recipes
EQ-TMX-02The single production schedule that exhausts all three supplies. Total output is kg, matching the total mass received.
Ingredient balance system, revised recipes
EQ-TMX-03After standardising every grade at one-third peanuts. The peanut equation now says only that total production is kg, so it carries no information beyond the total mass balance.
One-parameter family of feasible schedules
EQ-TMX-04The complete solution set of the revised system. Substituting these expressions into any balance equation cancels every occurrence of and reproduces the supply figure exactly.
Feasibility interval from non-negativity
EQ-TMX-05The physical bounds that reduce an infinite algebraic family to a finite set of runnable schedules; restricting to whole kilograms leaves choices.
Daily profit as a function of the free quantity
EQ-TMX-06Margins are 1.29\ and 2.05f = 825\.
Profit after the standard-mix price cut
EQ-TMX-07Cutting the standard price to 5.25\ and reverses the slope. The optimum moves to , yielding 2{,}664.60$ and zero standard-mix production.
Variable Definitions
| Symbol | Name | Meaning | Domain / type |
|---|---|---|---|
| Bulk mix quantity | Kilograms of bulk trail mix produced per day | non-negative real | |
| Standard mix quantity | Kilograms of standard trail mix produced per day | non-negative real | |
| Fancy mix quantity | Kilograms of fancy trail mix produced per day; the free quantity under the revised recipes | non-negative real | |
| Recipe coefficient | Kilograms of ingredient in one fifteen-kilogram batch of grade | non-negative real | |
| Daily supply | Kilograms of ingredient received and stored each morning | positive real | |
| Unit margin | Selling price less production cost per kilogram of grade | real currency per kg | |
| Daily profit | Total margin realised by a production schedule | real currency | |
| Degrees of freedom | Number of production quantities that may be chosen once all balances are imposed | non-negative integer |
Worked Numerical Example
Problem statement
Under the revised recipes — bulk , standard , fancy kilograms of raisins, peanuts and chocolate per fifteen-kilogram batch — determine every production schedule that exactly consumes the daily supply of kg raisins, kg peanuts and kg chocolate, then select the schedule that maximises daily profit at margins of 1.29\ and 2.05$ per kilogram.
Write the three balance equations
Producing kilograms of bulk mix means batches, each containing kg of raisins, so raisin consumption from bulk production is . Assembling all three ingredients and clearing the common denominator of gives an equivalent integer system:
Note the redundancy in the peanut equation
Dividing the second equation by gives : the peanut balance says only that the total output equals the total mass received. It is therefore a total mass balance in disguise and adds no constraint beyond what the other two equations already carry once combined. Two independent constraints on three unknowns leave one degree of freedom.
Solve for two quantities in terms of the third
Take as the free quantity. From the total balance, . The raisin equation gives . Subtracting six times the first from the second yields , and then .
Verify against every balance
Substitution must reproduce each supply figure with the terms cancelling exactly. Raisins: . Peanuts: . Chocolate: . All three close for every value of .
Apply the physical bounds
Negative production is meaningless. requires ; requires . The quantity itself is non-negative throughout that range, so the feasible set is the closed interval — integer schedules, all of which exhaust the day's deliveries.
Express profit in the free quantity
Profit is quantity times margin, summed over grades. Substituting the parameterised quantities collapses a three-variable objective into a one-variable one:
Optimise over the interval
The coefficient of is negative, so profit decreases as fancy-mix production rises. The maximum is therefore at the lower endpoint , which gives and . Daily profit is .
Test the sensitivity to price
If the standard-mix selling price falls to 5.25\ and the objective becomes . The slope is now positive, so the optimum moves to , giving , and 2{,}664.60$. The feasible interval is untouched; only the choice within it changes.
The revised recipes leave one degree of freedom, so distinct schedules consume the day's raw materials exactly. Selecting on profit gives kg bulk, kg standard and kg fancy for a daily profit of 2{,}805\ per day more than the single forced schedule available under the original recipes, purely because a constraint was relaxed. The optimum sits at a boundary of the feasible interval, so the recommended schedule discontinues one product line entirely; that is a characteristic outcome of a linear objective and should be flagged to management rather than presented as an incremental adjustment.
Applications & Industry Use
Gasoline pool blending
Refinery blending combines reformate, alkylate, butane and cracked naphtha to hit octane, vapour pressure and sulphur specifications simultaneously. Each property balance is linear in the component volumes, and the resulting system typically leaves several degrees of freedom that are then resolved against component cost — the same structure as the trail mix problem at industrial scale.
Charge calculation for an alloy melt
Achieving a target composition from scrap, virgin metal and master alloys means solving one mass balance per controlled element. A unique solution means the charge is fully determined; remaining freedom is used to minimise cost or to favour cheaper scrap grades while holding residual elements below their limits.
Least-cost ration formulation
Animal feed is blended from grains, oilseed meals and supplements to meet protein, energy, fibre and micronutrient targets. The nutrient balances form a linear system; because ingredient prices move weekly, the useful output is not a single formula but the family of compliant formulas over which cost is minimised.
Concrete mix proportioning
Cement, supplementary cementitious materials, aggregate fractions and water are proportioned to satisfy volume, paste content and water-to-binder ratio requirements. These are linear balances in the constituent masses, and the residual degrees of freedom are exercised against strength, durability and embodied-carbon objectives.
Excipient blending to a fixed dose
A tablet formulation must deliver a fixed mass of active ingredient while meeting total mass, disintegrant fraction and lubricant fraction targets. The balances are linear in excipient quantities, and the analysis identifies immediately whether the specification is achievable, uniquely determined, or open to reformulation.
Chemical dosing and stream mixing
Blending source waters and dosing chemicals to hit hardness, alkalinity and chloride targets is a mass balance in the flow rates. Where the system is inconsistent, no blend of the available sources can meet the specification — a result the algebra returns before any plant trial is run.
Design Considerations
Recognise a redundant balance before drawing conclusions
In the revised recipes the peanut equation reduces to a statement of total mass, which the other equations already imply once combined. Redundant balances are common wherever recipes are normalised to a common total, and mistaking one for an independent constraint leads to a claim of a unique solution where a family in fact exists. Reducing the coefficient matrix reveals the redundancy mechanically.
The algebraic solution set is larger than the physical one
Linear algebra returns every mathematical solution, including those with negative production. Non-negativity, minimum batch sizes, integer packaging counts and equipment capacity all cut the algebraic set down. Report the algebraic family and the feasible subset separately; conflating them either overstates flexibility or hides options that a capacity change would unlock.
Expect corner solutions from a linear objective
Optimising a linear objective over a bounded feasible region always drives the answer to a boundary point, which typically means shutting down at least one product line. This is mathematically correct and often commercially unacceptable. If a balanced portfolio is required, add explicit minimum-production constraints or change the objective — do not override the optimiser's answer informally.
Watch for degeneracy at the switching price
For this plant, a standard-mix price of 5.292f\, and the optimiser's choice among them is arbitrary. Near that price the recommended schedule is extremely sensitive to small data changes, so the correct deliverable is a sensitivity range, not a point recommendation.
Exhausting supply is a constraint, not an objective
The requirement that every kilogram received be consumed is what makes the balances equalities rather than inequalities, and it is what makes the solution set so tight. Relaxing it to turns the problem into a linear program with a much larger feasible region and usually a better objective value. Whether the equality is a genuine requirement, driven by freshness or storage turnover, should be confirmed rather than assumed.
Keep units and denominators explicit
The recipe coefficients are masses per fifteen-kilogram batch, so every term needs a factor of to convert product kilograms into ingredient kilograms. Clearing the denominator early gives an integer system that is easier to reduce by hand and exact in rational arithmetic, but the conversion factor must be recorded so the answer is reported in kilograms of product rather than batches.
Standards & Codes
Notation, interchange and numerical standards that govern how this material is written down, stored and computed in production systems.
| Reference | Title | Relevance to this topic |
|---|---|---|
ISO 80000-1 | Quantities and units — Part 1: General | Establishes quantity calculus and dimensional consistency. Every term in a blending balance must carry the dimension of mass; a dimensional check catches most recipe-transcription errors before any solving begins. |
ISO 22000 | Food safety management systems | Requires traceability of formulation and batch composition. A documented blending calculation, including the solution set and the schedule selected from it, forms part of the production record for a food manufacturing operation. |
ISO 80000-2 | Quantities and units — Part 2: Mathematics | Fixes the notation used for indexed coefficients, summation and set membership so that a formulation model is interpretable across engineering teams and software tools. |
IEEE 754-2019 | IEEE Standard for Floating-Point Arithmetic | Governs the arithmetic used by planning software. Recipe fractions such as are not exactly representable in binary floating point, so an equality-constrained balance never closes to exactly zero residual. |
MPS format (mathematical programming system) | De facto interchange format for linear programs | The standard encoding for passing a constrained blending problem to a commercial solver once inequalities, bounds and an objective have been added to the balance equations. |
Material Selection
For a mathematical topic, "material" is the numeric representation: the scalar field, storage format and precision the computation is built from.
| Representation | Select when | Trade-off |
|---|---|---|
| Exact rational arithmetic | Recipe coefficients are given as simple fractions and the analysis must prove that a balance closes exactly. | Eliminates any question of residual tolerance and makes the redundancy of a dependent balance provable, but is unavailable in most spreadsheet and planning tools. |
| Integer arithmetic after clearing denominators | Hand computation and verification of a small formulation system. | Keeps every intermediate value exact and readable, but requires care to convert the final answer back into product mass units. |
| IEEE 754 binary64 | Routine production planning inside a spreadsheet, ERP module or scripting environment. | Fast and universally available, but recipe fractions round, so equality balances must be tested against a tolerance scaled to the batch size rather than against zero. |
| Fixed-decimal currency arithmetic | The profit or cost objective is evaluated for reporting rather than for ranking alternatives. | Avoids the rounding artefacts that make two schedules appear to differ by a fraction of a cent, but must not be used inside the optimisation itself where accumulated rounding can flip a comparison. |
| Integer decision variables | Production is packaged in discrete bag or pallet counts rather than continuous kilograms. | Reflects the real decision granularity, but converts a directly solvable linear system into an integer program whose solution cost grows sharply with the number of products. |
| Interval arithmetic on recipe coefficients | Ingredient composition varies between deliveries and the schedule must remain feasible across that variation. | Produces bounds on the feasible interval that are robust to supply variability, at the cost of wider and sometimes uninformative results. |
Manufacturing Notes
Implementation notes — how the result is actually produced by hand, by algorithm and by library, including cost and numerical behaviour.
Assembling the system from a recipe table
Read the recipe table by column, not by row: column of the table gives the coefficients of ingredient across all products, and that column becomes one equation. Transposing this step is the single most common assembly error, and it produces a system that is dimensionally valid and completely wrong.
Solving by hand and by machine
A three-by-three balance system is reduced by hand in a few minutes using elimination on the augmented matrix. In software, numpy.linalg.solve handles the square, uniquely determined case; when a balance is redundant the matrix is singular and solve raises an error, at which point numpy.linalg.lstsq or a symbolic reduction is needed to expose the solution family rather than to fail.
Verification discipline
Always substitute the parameterised solution back into the original balances with the parameter left symbolic. Every coefficient of the free quantity must cancel and every constant must match its supply figure. Checking a single numerical instance is a weaker test that passes even when the parameterisation is wrong in its slope.
Scaling to industrial size
A refinery blending model may carry hundreds of components and dozens of specification balances. The structure is unchanged, but the balances become inequalities, bounds are added on every component, and the problem is handed to a simplex or interior-point solver. The linear-algebra step survives as the equality-constrained core the solver works within.
Presenting the answer to a decision maker
The useful deliverable is not a single schedule but three items: the family of compliant schedules, the feasible range of the free quantity, and the objective evaluated across that range. That form supports a decision under changing prices without re-running the analysis, and it makes the switching price visible as the point where the recommendation flips endpoints.
Failure Modes & Common Mistakes
| Failure mode / mistake | Impact | Root cause | Prevention & detection |
|---|---|---|---|
| Transposing the recipe table during assembly | high | Building one equation per product instead of one per ingredient, so rows and columns of the coefficient array are swapped. | State explicitly that each equation represents a conserved ingredient, and check that the right-hand side of each equation is that ingredient's supply figure. |
| Reporting an infinite solution set as a single answer | high | A solver returns one particular solution from a family, and the free quantity is never identified. | Compare the number of independent equations against the number of unknowns before accepting any answer; if fewer, report the parameterisation. |
| Ignoring non-negativity | high | Presenting an algebraic solution containing a negative production quantity as a runnable schedule. | Apply the sign constraints to every parameterised expression and report the resulting bounds on the free quantity alongside the family. |
| Optimising before establishing feasibility | medium | Maximising the objective over the unbounded algebraic family, which drives the free quantity to an unattainable extreme. | Determine the feasible interval first, then evaluate the objective only at its endpoints. |
| Missing a redundant balance | medium | Assuming three equations in three unknowns must be independent, and concluding that a unique schedule exists when a family does. | Row-reduce the coefficient matrix and count non-zero rows rather than counting equations as written. |
| Confusing sale price with margin | medium | Building the objective from selling prices without subtracting production cost, which reverses the ranking of the grades. | Compute and tabulate the per-kilogram margin for each product as a separate step before forming the objective. |
| Testing an equality balance against exact zero in floating point | medium | Recipe fractions such as are not exactly representable, so a correct schedule leaves a residual of order . | Test the residual against a tolerance proportional to the supply magnitude, or clear denominators and work in integers. |
| Presenting a degenerate optimum as a firm recommendation | low | At the switching price the objective is flat across the whole feasible interval and the solver's choice is arbitrary. | Report the objective slope alongside the recommendation and flag any case where its magnitude is small relative to the price uncertainty. |
FAQs
Why does adjusting the recipes change a unique answer into infinitely many?
Standardising every grade at one-third peanuts makes the peanut balance equivalent to a total mass balance, which the other equations already imply once combined. The system loses an independent constraint while keeping three unknowns, so one degree of freedom appears. In matrix terms the rank drops from three to two, and the number of free variables is the difference between the count of unknowns and the rank.
Is a production schedule with more freedom actually better?
In this case yes, and measurably so: the best schedule under the revised recipes earns 2{,}805\ under the original ones, because there is now a set of compliant schedules to choose from rather than a single forced one. More generally, degrees of freedom are options, and options have non-negative value provided the objective is correctly specified.
Why does the optimum always land at an endpoint?
Because the profit function is linear in the single free quantity, so it is monotone over the feasible interval and attains its maximum at one end. The same reasoning extends to many variables: a linear objective over a bounded polytope attains its optimum at a vertex, which is the structural fact underpinning the simplex method.
What happens if no schedule can consume the supplies exactly?
The balance system is inconsistent and the solution set is empty. Row reduction reveals this as a leading one in the constants column of the augmented matrix. Operationally it means the supplies cannot be matched by any combination of the available recipes, and the response is to change the delivery quantities, add a product, or relax the equality to allow carry-over stock.
Does the optimal answer really recommend shutting down a product line?
Yes. At the original prices the optimum is kg fancy and kg standard, with no bulk mix produced at all; after the price cut, standard drops to zero and bulk returns at kg. Corner solutions are the norm for linear objectives. If maintaining presence in every market matters, that requirement must be entered as an explicit minimum-production constraint rather than applied after the fact.
How sensitive is the recommendation to the selling price?
Extremely sensitive at one specific point. A standard-mix price of 5.292\. Above that price the optimum sits at the lower endpoint, below it at the upper endpoint, and the recommendation flips discontinuously across the threshold.
Is this a linear algebra problem or a linear programming problem?
Both, in sequence. Linear algebra determines the complete set of schedules satisfying the equality balances and how many degrees of freedom remain. Linear programming takes over once inequalities and an objective are added. The algebraic step is not optional preparation — it is what tells you whether any freedom exists to optimise over.
References
- Beezer, R. A. A First Course in Linear Algebra, Version 0.70. University of Puget Sound, 2006. Section WILA, Subsection A. Licensed under the GNU Free Documentation License v1.2.
- Dantzig, G. B. Linear Programming and Extensions. Princeton University Press, 1963.
- Chvátal, V. Linear Programming. W. H. Freeman, 1983.
- ISO 80000-1:2022, Quantities and units — Part 1: General. International Organization for Standardization.
- Williams, H. P. Model Building in Mathematical Programming, 5th edition. Wiley, 2013.
AI Suggested Questions
- Rework this blending problem with the supply figures treated as upper bounds rather than exact requirements, and show how much the optimal profit improves.
- Add a fourth trail mix grade with a recipe of my choosing and determine how many degrees of freedom the balance system then has.
- Derive the standard-mix selling price at which the optimal schedule switches endpoints, and explain what happens exactly at that price.
- Show me the coefficient matrix of the revised system and its reduced row-echelon form, and point to the row that reveals the redundant balance.
- Formulate the same problem as a linear program with minimum production levels for every grade, and compare the optimum against the unconstrained answer.
- How would ingredient-composition variability between deliveries change the feasible interval for the fancy mix quantity?
Related Calculators
Enter a recipe table and supply figures to obtain the full family of compliant schedules and its degrees of freedom.
Linear System SolverSolve and report consistency, rank and the vector form of the solution set.
Feasible Range CalculatorApply non-negativity and capacity bounds to a parameterised solution family and return the interval of admissible parameter values.
Linear Margin OptimiserEvaluate a linear profit objective across a feasible interval and identify the optimal endpoint and the switching price.
