Don’t forget the kerf of the saw. And you might want to square the end of the 2x4 before you start depending on the project. And “lots” probably might not lead to a good answer (e.g. eleven times as many 7" pieces as 19" ones).
Define the problem and variables:
Let x be the number of 19" pieces to cut from each 2x4, and y be the number of 7" pieces to cut from each 2x4.
Define the objective function:
The objective is to minimize the waste, which can be represented as (96 - (19x + 7y)), as 96 is the length of each 2x4 and (19x + 7y) is the total length of pieces cut from it.
Set up the constraints:
You have the constraint that the total length of pieces cut from each 2x4 cannot exceed 96 inches, so the constraint is (19x + 7y <= 96).
Use Mathematica to solve the linear programming problem:
(* Load the LinearProgramming package *)
Needs[“LinearProgramming`”]
(* Define the objective function coefficients and constraints *)
objectiveCoefficients = {19, 7};
constraintsMatrix = {{19, 7}};
constraintsVector = {96};
(* Set up the optimization problem *)
solution = LinearProgramming[objectiveCoefficients, constraintsMatrix, constraintsVector];
(* Extract the values of x and y from the solution *)
{x, y} = solution;