Skip to main content
1-Visitor
January 7, 2019
Solved

finding minimum of multiple variable absolute function

  • January 7, 2019
  • 3 replies
  • 3803 views

please see attached file. i am trying to use the MINIMIZE function to find both the minimum value of the absolute function and the corresponding variable. as a result this variable would be a function of the remaining variable(s). i tried this with the ROOT function and it works. not sure why it would not work for MINIMIZE function. any help is very appreciated. thanks!

Best answer by Werner_E

OK, got it!

Sometimes its really easier than thought at first.

The trick is to exchange the two arguments:

B.png

 

3 replies

23-Emerald IV
January 7, 2019

Check the help documentation on the usage of the MINIMIZE function. You will find that it can only be used with a solve block. It is not intended to be used to find the minimum of a function as you may be trying. It is intended to find parameters in a system that minimize the error between actual values of a function and a criterion.

 

In general, to find the minimum of a function, calculate its derivative, find the roots (yes!) of that derivative and inspect which of them produce a minimum of the function.

But you can abuse minimize for that as well:

LM_20190107_Minimize.png

It's abuse, and you should handle it with care. Note for example what happens if you (ONLY!) change the exponent in the function f(x) from 2 to 3.

 

Success!
Luc

jasonbig1-VisitorAuthor
1-Visitor
January 7, 2019

thanks for the reply.

i actually tried finding the root of the derivative first, but for the absolute function, it gives me an error message "Encountered a floating point error". if there is a way around that, it will work for me too. please see attached.

 

i also created solve block and try to follow the documentations and the examples i saw, it still gives me an error. i guess like you said, the function MINIMIZE is not meant to be used this way.

 

then, is there another function that i should try? it seems what I am trying to do is pretty basic, finding the solution of a variable (as a function of the remaining variables) that gives the minimum of the mother function

23-Emerald IV
January 7, 2019

I see (thanks SMath).

So your function is f(x,y)=abs(3*(x^2 - x)-2*(y+1)). That is a parabola in x, that is shifted up and down by parameter y, and then you have to take the absolute value of the parabola. The valley of the parabola occurs for the same value of x, independent of y. So whenever y is low (possibly negative) enough, the minimum occurs in between where 3*(x^2-x) = 0, then x=0 or x=1, the middle is x=1/2. The parameter y only shifts the height of the minimum. The function becomes exactly zero when x=1/2 and 3*(x^2 - x)-2*(y+1)=0 that is when y=-11/8. So as long as y<= -11/8, the minimum occurs at x=1/2, and the minimum is abs(-11/4-2*y). If y>-11/8, two zero's on either side of x=1/2 occur. But the two minima (due to the absolute) will always be 0.

LM_20190107_Minima.png

Success!

Luc

25-Diamond I
January 8, 2019

I can confirm that "Minimize" does not need a solve block to work (if you don't have to apply additional constraints) and that even in combination with the usually quite beasty absolute function should work.

You had used the wrong syntax. For a single argument function f(x):=... the syntax would be minimize(f,x) and NOT minimize (f(x),x).

In real Mathcad (as opposed to Prime) we can define a single argument function by simply using the two argument function and providing just the first argument. See the screenshot. All works fine with constant values of x.

But when I try to turn that into a function, Mathcad moans about f not being defined. It should work but the Minimize function sometimes is beasty, too. The really annoying part is that I think I solved a similar problem quite a long time ago but simply can't remember how 😞

 

Setting the first derivative to zero can't work in case of your function as the derivative is NOT zero anywhere and your function is not differentiable at the position in question anyway.

Using root the find the point of  zero works in your case, but of course would fail if the function is changed to something like f(x,y):=| .... | - 5

 

 

B.png

Werner_E25-Diamond IAnswer
25-Diamond I
January 8, 2019

OK, got it!

Sometimes its really easier than thought at first.

The trick is to exchange the two arguments:

B.png

 

jasonbig1-VisitorAuthor
1-Visitor
January 8, 2019

Thank you so much. I tried this approach and it works!

Really appreciate your help!

jasonbig1-VisitorAuthor
1-Visitor
January 8, 2019

Many thanks to everybody for taking the time to help me solve this problem. It is really helpful. I learned a lot. I tried Werner_E's approach and it is working so far. Yay! 

 

Thank you all!