0

I have these three equations:

f = a*b*(a + b - 4*x - 2*y - z) + x*(x + y)*(2*x + y + z);
g = (a*b*((a + b)*(a + b - 4*x - 2*y - z)^2 + x*(x + y)*(2*x + y + z) - 12*c*d*(a + b - c - d - 4*x - 2*y - z)) - x*(x + y)*(2*x + y + z)*(5*x*(x + y) + 2*x*z + y^2 + y*z))/12;
h = 2*(c + d) + 4*x + 2*y + z

I want to get values for x, y, and z in terms of a, b, c, d, and dMax under the following circumstances:

  • the variables a, b, c, d, and dMax stand for arbitrary positive real numbers
  • x, y, and z are positive real numbers
  • f == 0
  • g == dMax
  • h is minimized (a positive real number as close to zero as possible)

How would I input this in Wolfram Language? The documentation for Minimize[] seems to say that it only works on one function at a time, and Solve[] doesn't seem to handle minimization unless I'm missing something.

EDIT

Based on @Michael E2's comments and @Ulrich Neumann's answer I tried entering the following:

$PrePrint = InputForm;
f = a*b*(a + b - 4*x - 2*y - z) + x*(x + y)*(2*x + y + z);
g = (a*b*((a + b)*(a + b - 4*x - 2*y - z)^2 + x*(x + y)*(2*x + y + z) - 12*c*d*(a + b - c - d - 4*x - 2*y - z)) - x*(x + y)*(2*x + y + z)*(5*x*(x + y) + 2*x*z + y^2 + y*z))/12;
h = 2*(c + d) + 4*x + 2*y + z;
mini[a_, b_, c_, d_, dMax_] := Minimize[{h, {f == 0, g == dMax, a > 0, b > 0, c > 0, d > 0}}, {x, y, z}];
mini[a, b, c, d, dMax]

The program sits at around 70-90% CPU usage for hours without resolving. Is there a better way to do this? Or is there anything obvious I can do to the input equations to make the computation more efficient?

Lawton
  • 103
  • 5
  • General tip (does not solve problem): Avoid capitals, esp. ones like C and D which are Protected system symbols. – Michael E2 May 28 '23 at 21:51
  • @MichaelE2 Besides being against best-practice, would using C and D cause any problems in this specific case? – Lawton May 29 '23 at 20:07
  • It might, though it's unlikely. Sometimes internal functions use Quiet[] to suppress error messages, so just because there were no errors does not rule out a problem. That there are no errors is substantial evidence that C and D are not the issue, but you can't be completely certain. For instance, if Mma tries to assign C or D a value, then there would probably be a problem (try out Block[{D = 4}, D[x^2, x]], and no error message). I tried Ulrich's code or one similar (he didn't distinguish D/d) and it did not finish in a reasonable amount of time. – Michael E2 May 29 '23 at 20:34
  • @MichaelE2 I updated my functions to use lowercase letters and renamed the old d to dMax, as it seems like multi-character variable names are allowed. Are there any other best-practices I should be aware of? – Lawton May 29 '23 at 22:28
  • Probably not. Though using = for variable assignments such as f = x^2 and := for function assignments such as f[x_] := x^3; is common. (So the '=' you had originally is fine.) The list I linked earlier has grown to have excessively many pieces of advice. But it was originally meant to be a first resource for new users. The 2nd & 3rd groups are mostly important; if you use numerical methods, the NumericQ one is important. – Michael E2 May 29 '23 at 22:46
  • For your problem above, realize that as the number of parameters and variables grow in a nonlinear problem, the complexity can grow quite fast. Mma will generally analyze the parameters, because it tries to prove to itself that it has found a minimum. After it has found all the critical points. In theory, being a problem involving polynomials with polynomial coefficients, it can be solved. But it might take and excessive amount of time. (My CPU ran at nearly 800% for maybe 20 min. before I killed it.) If you can simplify your problem at all, it might help significantly. – Michael E2 May 29 '23 at 22:52
  • @MichaelE2 Unfortunately this is as simple as I've been able to make it so far... the g function started out over 2700 characters long before extensive work in cancelling and noticing that a subset of its terms contained a factor of the f function (which will be set to zero) and could thus be cut out. I'll keep working on it though. – Lawton May 30 '23 at 01:00
  • @Lawton Still you didn't modify the definitions f:=...,g:=...,h:=... to f=...,g=...,h=.. as proposed by MichaelE2 – Ulrich Neumann May 30 '23 at 08:06

1 Answers1

0

modified

Perhaps

(N)Minimize[{h,{f==0,g==d,a>0,b>0,c>0,d>0}},{a,b,c,d}]

QP changed content of the question. Now he's looking for optimal {x,y,z}:

mini[a_, b_, c_, d_, dMax_] := Block[{
J = 2*(c + d) + 4*x + 2*y + z,
zwang = {a*b*(a + b - 4*x - 2*y - z) + x*(x + y)*(2*x + y + z) == 0,
(a*b*((a + b)*(a + b - 4*x - 2*y - z)^2 + x*(x + y)*(2*x + y + z)-12*c*d*(a + b - c - d - 4*x - 2*y - z)) - x*(x + y)*(2*x + y +z)*(5*x*(x + y) + 2*x*z + y^2 + y*z))/12 == dMax}},

NMinimize[{J, zwang}, {x, y, z}]]

example

mini[1, 1, 1, 1, .1]
(*{4.1, {x -> 1., y -> -2.9, z -> 1.9}}*)

Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
  • I tried NMinimize[{h, {f == 0, g == d, A > 0, B > 0, C > 0, D > 0}}, {A, B, C, D}] and the program ran for about half an hour at around 40% CPU usage and using steadily increasing amounts of RAM until it reached 63.8 out of 64 GB, then another ten minutes or so at 100% hard-disk utilization, before crashing with an error that there was no more memory available. I then tried Minimize[{h, {f == 0, g == d, A > 0, B > 0, C > 0, D > 0}}, {A, B, C, D}], and it's been running at between 70% and 90% CPU utilization for five hours with no sign of progress. Is this expected or is something wrong? – Lawton May 29 '23 at 18:22
  • `Block[{x = 1, y = 1, z = 1}, NMinimize[{h, {f == 0, g == d, a > 0, b > 0, c > 0, d > 0}}, {a, b, c, d}]

    ]` evaluates in .5 seconds!

    – Ulrich Neumann May 29 '23 at 20:29
  • I think I didn't convey everything to you fully. D and d were separate variables. I've updated my question to not use single-uppercase-character variable names per Michael E2, so now the function g should now be equal to dMax. I also want to solve for x, y, and z in terms of the other named variables; setting x, y, and z to a specific value seems counterproductive. I'm now trying Minimize[{h, {f == 0, g == dMax, a > 0, b > 0, c > 0, d > 0}}, {x, y, z}]; I'll update with how it goes. – Lawton May 29 '23 at 22:35
  • @Lawton You changed the question without notification. Now you're looking for optimal x,y,z!!! – Ulrich Neumann May 30 '23 at 07:48
  • I did not change the content of my question with regards to what variables I wanted to solve for. You can look at the edit history yourself to confirm that. – Lawton May 30 '23 at 14:43
  • Using your new suggestion, I get the error NMinimize::bcons: The following constraints are not valid: {a b (a + b - 4 x - 2 y - z) + x (x + y) (2 x + y + z) == 0, (-(x (x + y) (2 x + y + z) (y^2 + 5 x (x + y) + 2 x z + y z)) + a b ((a + b) (a + b - 4 x - 2 y - z)^2 - 12 c d (a + b - c - d - 4 x - 2 y - z) + x (x + y) (2 x + y + z)))/12 == (dMax_)}. Constraints should be equalities, inequalities, or domain specifications involving the variables. – Lawton May 30 '23 at 14:55
  • At the end there it looks like you have dMax_ (with an underscore). Try removing that (not from the left-hand side of mini[... dMax_] =, it's needed there; but from the right-hand-side of that statement). – evanb May 30 '23 at 17:52
  • @evanb You're right, I had forgotten to remove that underscore. After fixing that I no longer get an error, but I left the program running for 12 hours and it didn't return any result. – Lawton Jun 01 '23 at 17:08
  • @UlrichNeumann I'd like to get symbolic expressions for x, y, and z in terms of a, b, c, d, and dMax as variables, rather than getting specific numeric values for x, y, and z for specific numeric values of a, b, c, d, and dMax. – Lawton Jun 01 '23 at 17:10
  • Do you have reason to expect a symbolic expression for the global minimum exists? – evanb Jun 01 '23 at 17:45