Get Help

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Re: finding minimum of multiple variable absolute ...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
12:20 PM

01-07-2019
12:20 PM

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!

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
08:05 PM

8 REPLIES

Highlighted
##
##### Re: finding minimum of multiple variable absolute function

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
01:01 PM

01-07-2019
01:01 PM

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:

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
01:30 PM

01-07-2019
01:30 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
04:11 PM

01-07-2019
04:11 PM

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.

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
07:29 PM

01-07-2019
07:29 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
08:05 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
08:16 PM

01-07-2019
08:16 PM

For some functions a single guess value y.guess might not be appropriate for the whole range of x-values of interest. In this case it might be a good idea to make the guess value dependent on the argument x and add it as an additional argument of the y.opt function.

The example below shows how to do it and also uses a slightly more complicated function f.

Worksheet in MC15 format attached.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
11:06 PM

01-07-2019
11:06 PM

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

Really appreciate your help!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-07-2019
11:08 PM

01-07-2019
11:08 PM

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!

Top Tags