I want to find the best arrangement for n boxes (dimensions: c * d) on a platform (dimensions: a * b). I presumed to write something like:

FindMinimum[(a-p*c)*(b-m*d), p, m]

Where p is the numbers of boxes to place on the a-side of the platform and m the same for the b side. Why doesn't it work? (I'd like to find the numbers of boxes to place per each side of the platform.) p+m=8 I want to minimize the grey area

  • 2
    $\begingroup$ FindMinimum is only used for numerical computations. First try assuming that some parameters are positive and use the function Minimize. For example take a look at this Assuming[ a > 0 , Simplify[Minimize[a*x^2, x]] ] $\endgroup$ Nov 9, 2016 at 12:31
  • 1
    $\begingroup$ Minimize[(a - p*c)*(b - m*d), {p, m}] works, but the solution (either $a b$, $0$, or $\infty$) can be readily derived from (a - p*c)*(b - m*d) // Expand. $\endgroup$
    – Feyre
    Nov 9, 2016 at 12:35
  • $\begingroup$ 1. Can you explain the problem in more details? I don't understand what are the possible arrangements. 2. KnapsackSolve (new in v11) is probably better for this sort of problem. But I don't understand the problem, and if I'm not alone, better explanations are needed. 3. The syntax you used with FindMinimum is simply wrong. Don't guess and then wonder why it didn't work. Look it up! $\endgroup$
    – Szabolcs
    Nov 9, 2016 at 12:41
  • $\begingroup$ Thanks you all. 1) I don't know English well 2) I'm new at Mathematica, so I beg your pardon. I want to know how many boxes can fill the platform. So, as first attempt, I try to minimize the free space left after placing these boxes on a platform, and i presumed to minimize the product of the space that will be available on the a side (a - pc) * space available on the b side (b - md). I know there are other solutions but this is just a "starting point" and I want to use a function that find the minimum values. $\endgroup$
    – Luca
    Nov 9, 2016 at 13:19
  • 1
    $\begingroup$ I still don't understand, but maybe others do. Perhaps a drawing will help. Draw a platform and one possible arrangement. That will make everything very clear. $\endgroup$
    – Szabolcs
    Nov 9, 2016 at 13:34

1 Answer 1


You can try this for specific examples numerically (I dont see another option since you have to specify that the number of boxes have to be integers, as far as I could interpret your picture)

a = 15;
b = 7;
c = 3;
d = 2;
  (a*b - n1*c*d - n2*c*d)^2
  , Element[n1, Integers]
   && Element[n2, Integers]
   && n1*c <= a
   && n1*d <= b
   && n2*d <= a
   && n2*c <= b
   && 0<=n1 (*additional conditions*)
   && 0<=n2
 , {n1, n2}

{5625., {n1 -> 3, n2 -> 2}}

The result above tells you that the error in the objective function (a*b - n1*c*d - n2*c*d)^2 is 5625 when you use 3 boxes with their long side with length c parallel to the platform side with length a and 2 of the other boxes with length d parallel to a.

A analytical solution seems difficult since you have to consider only integers for n1 and n2 and they have to fulfill the conditions I also gave in the minimization.

  • $\begingroup$ What's the difference between n1 and n2? $\endgroup$
    – Luca
    Nov 9, 2016 at 16:17
  • $\begingroup$ n1 is the number of boxes with side c parallel to a (take a look at the first inequality I imposed in the minimization), while n2 is the number of boxes with side d parallel to a (connected to the third inequality). $\endgroup$ Nov 9, 2016 at 16:41
  • $\begingroup$ Ok, yes, thank you very much :D $\endgroup$
    – Luca
    Nov 9, 2016 at 16:43
  • $\begingroup$ @Luca you are welcome :D since you are new, don't forget to accept an answer if it solved your problem. that is useful for everybody. $\endgroup$ Nov 9, 2016 at 16:49
  • $\begingroup$ I want to make the assumption n1 and n2 are positive integer, what should I write? (in this moment I'm trying to implement the possibility to place boxes "tunerd", so I add n3 and n4, but it always return negative values) $\endgroup$
    – Luca
    Nov 9, 2016 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.