Skip to main content
1-Visitor
April 19, 2016
Solved

Minimize function strange result

  • April 19, 2016
  • 4 replies
  • 9365 views

Hi all,

I hope this is the right sub-forum to post this address.

I am trying to make use of some Mathcad in-built capabilities, like for instance the Minimize or Maximize function.

Please have a look at the attached file. I have some functions defined there which ultimately are used inside the final function called Function1 (blue background).

For Function1, I want to apply the mathcad defined Minimize function, which needs the variation intervals for the variables of the function to be defined (along with guess values). I can do that OK, and I do get a relevant result when applying the Minimize function on Function1 (the result consists of the variables values, within the defined interval for each variable, for which Function1 will be minimum). I store this result in the variable called "Result" and then I compute the value of the Function1 function with the elements of the "Result", aiming to obtain the minimum of Function1 (yellow background).

The problem that I have is that it does not seem to be a minimum; meaning I can find other values for the variables, within the defined intervals, for which the value of Function1 is even smaller (see area marked in green). So am I doing something wrong or is this simply a strange function?

Regards,

Cristian

Best answer by LucMeekes

OK, the reason why you  (Cristian and Rich) get the same result on the first run is due to the random number generation, which is pseudo random: Whenever Mathcad starts up with the same sheet, doing the same calculation(s), the sequence of random numbers is the same.

The reason you don't get (almost) exactly the 'absolute' minimum is because if you want that, you have to set the parameters correctly (that is to the edge), which is what I did in successive runs to verify Werner's observation. With every run I limited the range of each variable between a found minimum and the correct edge.

Luc

4 replies

25-Diamond I
April 19, 2016

Mathcad will find a relative minimum, no necessarily the absolute minimum.

Maybe your problem is conditioned in a way that you have a lot of local minima very near and changing the guess values slighty may yield one or the other.

Its strange that I get a better result when I increase the value of CTOL - would have expected the opposite effect.

cberceanu1-VisitorAuthor
1-Visitor
April 29, 2016

Werner Exinger wrote:

Mathcad will find a relative minimum, no necessarily the absolute minimum.

Maybe your problem is conditioned in a way that you have a lot of local minima very near and changing the guess values slighty may yield one or the other.

Its strange that I get a better result when I increase the value of CTOL - would have expected the opposite effect.

Werner, did you do anything else apart from assigning CTOL a value of 10^-1? Because if I do that, the result in my file does not really change! Please see the attached file called minmax_no_external_file_with_CTOL_set_to_0.1.xmcd

On the other hand, I was able to find a smaller value by doing these things simultaneously:

- decrease the value of CTOL (down to 10^-7)

- set the guess values at the beginning (or end) of their variation interval

By doing this, I did find a minimum slightly smaller than the one I could manually find, see attached file called minmax_no_external_file_with_guess_values_set_at_the_beginnig_of_the_variation_interval.xmcd

Now I would be close of trusting this minimum I found, but I am really puzzled by the 2754.3 value you present above and which I cannot replicate. Would you kindly screenshot the results of the minimize function (the value of the variables) that you get when setting the CTOL to 10^1 on your machine? Thanks.

Regards,

Cristian

25-Diamond I
April 29, 2016

> Werner, did you do anything else apart from assigning CTOL a value of 10^-1?

No, nothing. I just tried again with the same result. And I also get the same low result with CTOL set to 1 or even to incredible 10! Not sure, why this works.

But you have to set CTOL before the solve block (I used a global assignment for the screen shot) or via menu (Tools - Worksheet options - Built-in Variables).

EDIT: I just opened your file and get the same (low) result. See the screenshot:

I am using Mathcad 15 M030.

Here are the 12 values for easier copy and paste:

12.075438396003252

3.708e3

370.8

1.0150000000000001e-7

1.0000000000000222

0.05

1.2210011707882724e-5

1.2210011707882724e-5

1.2210011707882724e-5

0

1.2210011707882724e-5

8.676833784435876e-12

772.5

When I open the other file (with CTOL = 10^-7) I see the result 2886,2.

Werner

19-Tanzanite
April 19, 2016

So am I doing something wrong or is this simply a strange function?

Neither. It is the nature of non-linear solvers. They are iterative. They start at the guess values, then head downhill on the error surface until the error changes by less than a certain amount, and then stop. In Mathcad the built in variable CTOL determines what "less than a certain amount" means. So if your error surface has many local minima, or large areas that are nearly flat, the solver may not find the global minimum.

cberceanu1-VisitorAuthor
1-Visitor
April 25, 2016

Thank you for your replies!

I was out of office for a couple of days, but I will give it a try (playing with the CTOL value).

I am really curious to see what the real minimum of this function is!

25-Diamond I
April 25, 2016

A numeric algorithm will always present you a local minimum and it depends on the guess values, the given allowed tolerances and of course the nature of your function.

So you will need a lot of luck to find the absolute minimium of your function, I guess.

24-Ruby IV
April 25, 2016

Werner Exinger написал(а):

A numeric algorithm will always present you a local minimum and it depends on the guess values

See please Video Link : 1460

25-Diamond I
April 29, 2016

Playing around with a Monte Carlo simulation for a while (refining by narrowing the allowed range of the arguments) I come to the conclusion, that you get your minimum if you choose argument values from the end of your ranges - mostly the upper bounds (in red below), but three times the lower bounds (green) as well (Gain remains 1):

I suspect that you will not be able to beat 2886,038457 with arguments all within the allowed range.

Werner

23-Emerald IV
April 30, 2016

Checked.

You're right, Werner.

(OK, I beat it by 2e-11 , with a result of 2886.03845714428, but at the same input values.)

Luc

Incidentally,

I improved the Monte Carlo algorithm. It was transposing the variables matrix a bit too often. Now it runs 1 million runs in about 20 s on my machine.

cberceanu1-VisitorAuthor
1-Visitor
May 3, 2016

True,

I also get slightly higher values at subsequent runs of the calculation in that file. And almost always they are higher than 2895 (hence also larger than the initial value of 2894.493).

I initially also though Luc might have run it for 10 million times and I tried the 10.000.000 number of runs but it fails with the "incorrect range for variable at index #2" error.

Cristian