0
$\begingroup$

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?

$\endgroup$
8
  • $\begingroup$ General tip (does not solve problem): Avoid capitals, esp. ones like C and D which are Protected system symbols. $\endgroup$
    – Michael E2
    May 28 at 21:51
  • $\begingroup$ @MichaelE2 Besides being against best-practice, would using C and D cause any problems in this specific case? $\endgroup$
    – Lawton
    May 29 at 20:07
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    May 29 at 20:34
  • $\begingroup$ @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? $\endgroup$
    – Lawton
    May 29 at 22:28
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    May 29 at 22:46

1 Answer 1

0
$\begingroup$

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}}*)

 
$\endgroup$
10
  • $\begingroup$ 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? $\endgroup$
    – Lawton
    May 29 at 18:22
  • $\begingroup$ 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! $\endgroup$ May 29 at 20:29
  • $\begingroup$ 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. $\endgroup$
    – Lawton
    May 29 at 22:35
  • $\begingroup$ @Lawton You changed the question without notification. Now you're looking for optimal x,y,z!!! $\endgroup$ May 30 at 7:48
  • $\begingroup$ 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. $\endgroup$
    – Lawton
    May 30 at 14:43

Your Answer

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

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