Skip to main content
1-Visitor
March 6, 2014
Question

Maximize/minimize

  • March 6, 2014
  • 5 replies
  • 12702 views

We are now starting on some of the more advanced features and have been playing around with Maximize and Minimize. I found the minimise not to want to solve and playing around further I cam across the interesting conclusion that Mathcad cannot accommodate multiple accurences of maximize or minimize in the same document.

I duplicated this into a simple sheet duplicating the exact same command next to each other except that the answer is stored into different variables. When moving the one above the other they alternate in solving. This is rather irritating as our model needs to use the data generated to in one case maximize a value and in another case minimize another, but the second one simply does not want to solve.

Has anyone come across the same. Are we doing something wrong or is this a problem in Mathcad.

Please assist

BWB

5 replies

24-Ruby IV
March 6, 2014

The problem with CTOL and TOL

We must do CTOL and TOL := 10^-10 or work with m not cm - see please the attach

1-Visitor
March 6, 2014

I do not see any difference changing the CTOl and TOL. Still doing the same. I on purpose deleted the units and only multiply that in in the last step. However, even if I remove them completely it still does the same.

24-Ruby IV
March 6, 2014

Barend Botha wrote:

I do not see any difference changing the CTOl and TOL.

abc.png

19-Tanzanite
March 6, 2014

Make the Minimize solve block a function - see attached.

Alan

1-Visitor
March 6, 2014

Making the minimize solve block a function now ignores the limitations given in the Given block, i.e. the limitation in this case is that the volume should be larger than 60 cub cm and both answers are smaller.

19-Tanzanite
March 6, 2014

Actually the condition you have is that the volume should be greater than or equal to 60, and it comes out to be 60. I did however, leave out your condition that height must be twice the width (because you hadn't specified it correctly and I forgot to put it back after deleting your statement!). The attached puts this back in.

Alan

25-Diamond I
March 6, 2014

I am not sure about the problem you are experiencing. I guess the problem you posted in your sheet is not the problem you actually want to solve. In your post you wrote that you want first to maximize one problem and use the results as guess values to minimize a second problem. In your sheet you are simply trying to do the same minimization twice which doesn't make much sense as does the condition >=60 instead of =60 as it must be clear the volume in the problem you posted has to be exactly 60 cm^3 (if a solution would be found for a greater volume you could cut the height and get a better solution).

Basically your sheet has the structure

Given

... constraint(s)

Sol:=Minimize(....)=

Sol:=Minimize(....)=

You have to think of "Given" and "Minimize" as opening and closing parenthesis.

So the second time Minimize is used standalone without a solve block (no associated Given). It will use no constraints and the current values of l.min etc. as guesses (which are the initial 1's in your sheet!). This standalone Minimize fails with an improper error message (variable not found) because we would get a minimum (w/o constraints) for variables being minus infinity.

If you move the second Minimize above the first it gets associated with the given and the other will be the one which is standalone.

So in case your original problem requires two different optimizations with different constraints, the solution is to use a solve block for the second optimizatioin, too. Keep in mind that constrains only are considered if the are stated IN the solve block (between Given and Maximize, minimize, Find, or ,,,,).

If the problem you posted really is the one you want to solve, see the attached file. There is no need for a second minimize.

If you chose the more elegant way and add units to your variables from the beginning as Alan had doen, you will have to change CTOL to a much smaller value than the default 10^-3 as Valery suggested because Mathcad will use its tolerances on the values in base units (meter in your case).

24-Ruby IV
March 6, 2014
25-Diamond I
March 6, 2014

OK, I have recreated the worksheet and set it up to be able to compare results with and without units for different values of CTOL with the exact solutions derived symbolically. The solutions depend rather heavy on the guess value, better guesses give better solutions. If we look at the 3D-plot we see that the area around the minimum is rather flat, so small steps will not change the surface area much and the algorithm stops (too soon) according to the convergence tolerance set. Given that 1cm^3 = 10^-6 m^3 I would have expected the same results for (no_units & CTOL=10^-3) and (units cm & CTOL=10^-9). This is pretty much true, but not exactly. Also for (no_units & CTOL=10^+3) I get similar results as with (cm units & CTOL=10^-3) which is also as expected. So far no bug, just a word of caution when using those numeric approximation algorithms with units different from the base units.

But .... from the previous posts it looks like different people get different results from the very same sheet. Can anybody confirm that with this sheet and post screenshots if he/she gets different results? The screenshots below are the result of using Mathcad 15 M030 under Win XP.

Minimize_Unit_Bug_1.png

Minimize_Unit_Bug_2.png

1-Visitor
March 7, 2014

Werner

For CTOL = 10^-3 I get the same, however, for 10^-6 and 10^-9 there is no solution when the units are not included, yet the values for the other solution are different and also differs from yours.

I am using Mathcad 15 M010 on Windows 7

25-Diamond I
March 7, 2014

I just loaded the file on a different machine (but still MC15 M035 on Win XP) and got the same results as those I posted the screenshots of. However with CTOL=10^-6 I also get no soulution without units. Better guess values cure the problem of course as the problem is quite sensible to the guesses.

But the different results you get a scary. Guess its not the operating system but the MC version (M010 vs M030)?