0

I want to have a function that based on length, width, and height (within a certain bound) minimizes the volume. But in addition to volume, I also want to calculate half_volume = volume /2.

My minimization algorithm successfully determines the correct height, width, and length (obviously the lower band values). But how do I extract the half_volume value?

def calcVolume(x):
    length = x[0]
    width  = x[1]
    height = x[2]
    volume = length * width * height
    half_volume = volume / 2
    return volume

sol = minimize(calcVolume, initial_guess, method = 'SLSQP', bounds = x_bounds,options = {'ftol': 1e-8, 'maxiter': 2000, 'disp': True})

Because I am running minimization, I can not return more than one output (which is volume in this case). If I print solution.x it will give me correct height, weight, and lenght as well as the minimized volume. How do I get access to half_volume?

martineau
  • 119,623
  • 25
  • 170
  • 301
Changoleon
  • 31
  • 4

1 Answers1

0

You can't get access to half_volume since the function is not returning it.

The only way to get to is through using the half_volume calculation outside the function like ...

def calcVolume(x):
    length = x[0]
    width  = x[1]
    height = x[2]
    volume = length * width * height
    return volume

half_volume = calcVolume(x) / 2
1__
  • 1,511
  • 2
  • 9
  • 21