cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Minimizing for a family of functions

AlvaroDíaz
12-Amethyst

Minimizing for a family of functions

Hi. How to minimize a family of functions over the same range with the same given-minimize block?

Regards. Alvaro.
39 REPLIES 39

When defining a function based on minimize (or maximize) you have to account for a little quirk in Mathcad. Any arguments for the function that are not variable being varied are passed to the function being minimized following the variables stated in the minimize statement. The function being minimized must be written to accept these additional parameters.
__________________
� � � � Tom Gutman

Amazing technique. Thanks a lot Tom.

Alvaro.
RichardJ
19-Tanzanite
(To:AlvaroDíaz)

On 10/24/2009 6:36:30 AM, adiaz wrote:
>Amazing technique.

Yes, but unfortunately one that does not work post version 11. SUC strikes again (it requires that f be a function, whereas in fmin(f,x):Minimize(f,x) it could be anything).

Richard

>...whereas in fmin(f,x):Minimize(f,x) it could be anything)<.
______________________

What about like I did ?

qMin(Obj,x):Minimize(Obj,x)

SUC has pestified Mathcad, and more generally the introduction of the unit system. The bug is that above 11, it does not understand that a dummy argument is a dummy argument. Does my work sheet works for you in 14 ? and for all. At some point, Mathcad will rate -100%. If 14 does not recognize a dummy argument, lost case. By removing the dummy functionality, PTC has demonstrated once more that they didn't know much about Mathcad as it was when it was Mathcad.

jmG
RichardJ
19-Tanzanite
(To:ptc-1368288)

On 10/24/2009 11:20:22 AM, jmG wrote:

>qMin(Obj,x):Minimize(Obj,x)

Why do you think changing the name from f to Obj would make any difference?

>SUC has pestified Mathcad, and
>more generally the
>introduction of the unit
>system.

It has nothing to do with units. SUC is the acronym everyone uses, but it's a misnomer. It should really be STC, where T stands for type. Or possibly STD, where D now stands for disease. Obj (or f) must be of type "function", and it's not. It's of type "any", and therefore it fails.

>If 14
>does not recognize a dummy
>argument, lost case.

What's dummy about the argument? It's the function name, and Minimize uses it as such.

Richard

Thanks Richard,

SUC (System Unit Checking) came from PTC.
OK, MCD 14 does not carry dummy,
that single stupidity zaps a huge % work sheets.

jmG
RichardJ
19-Tanzanite
(To:ptc-1368288)

On 10/24/2009 6:29:44 PM, jmG wrote:
>Thanks Richard,
>
>SUC (System Unit Checking)

S=Static

>came from PTC.

No, from Mathsoft

>OK, MCD 14 does not carry
>dummy,

Yes it does. There are no dummy arguments in the worksheet, and this has nothing to do with them.

Richard


It's not an inherent problem with SUC, but a bug in the implementation of SUC. SUC can deal with formal arguments that are functions, recognizing that from the usage. Note the signature of g, a function of a function and anything, resulting in another anything. But it fails with minimize, although the context should allow SUC to classify the first argument as a function. Perhaps it has to do with minimize not being an actual function (note the inability to get a signature for it) but a special form. As such, it presumably needs special code in SUC, code that was not provided.

I didn't do it previously, as I believe Alvaro uses MC11, but it is possible to do the same in MC14 by using an extral level of indirection so that the function argument to minimize is a worksheet variable rather than an argument.
__________________
� � � � Tom Gutman

On 10/24/2009 4:39:39 PM, Tom_Gutman wrote:
>It's not an inherent problem with SUC, but a bug in the implementation of SUC. (...)

Interesting. This says that probably this bug could be corrected in mc15. Or in other words, hope is the last thing in dead. But actually my hope is an option at worksheet level to disabling SUC.

>I didn't do it previously, as I believe Alvaro uses MC11 (...)

You are right. And your help is very appreciated.

>but it is possible to do the same in MC14 by (...)

I see if next week can check your file in mc14.

I'm writing a function fmin(f, a, b) to find min (f) in the range (a,b) for f one variable function, but not finished yet. As question: this kind of functions can work in mc14, as functions of functions?

My functions, for example, must to work with f(x):=x fmin(f,0,1)=0 and directly for fmin(exp,0,1)=1.

Regards. Alvaro.

>...I'm writing a function fmin(f, a, b) to find min (f) in the range (a,b) for f one variable function ...<<br> ________________________

Not clear ! You can consult the long collection "Mathcad for Engineers Give_Find" posted within last 3 weeks. You will find several examples of such applications.

jmG

Functions with a signature, that is with a fixed number of well defined arguments, can be passed as arguments to another function. That includes all user defined functions. Built in functions that take a variable number of parameters cannot be passed as arguments. But for specific cases one can define a user function that can be so passed. Thus max cannot be passed as an argument (as it takes a variable number of arguments), but for specifically two arguments one can define max2(x,y):=max(x,y) which can be so passed.
__________________
� � � � Tom Gutman

On 10/24/2009 7:04:54 PM, Tom_Gutman wrote:
>Built in functions that take a variable number of parameters cannot be passed as arguments.

Ahahahaha! This is what have me confusing why sometimes I can pass functions as arguments and mysteriously, my works goes into the mathcad errorland. I'm not the first saying you that make all this free notes enjail into a something like a book.

Regards. Alvaro.

Here's the version that works in MC11 and MC14. Also how to use arrays to automatically iterate over the target functions.
__________________
� � � � Tom Gutman

On 10/25/2009 1:03:52 AM, Tom_Gutman wrote:
>Here's the version that works in MC11 and MC14.

And with more elegance, no way.

Attached, the never well ponderated brute force attack.

Regards. Alvaro.

>And with more elegance, no way.<<br> ________________________________

Your program is useless. Minimize/Maximize are based on Brent method and more than simple and elegant by themselves, why invent one more not working ? You could try Valery "Golden ratio". Both, Tom and jmG work fine, but both have some limitations. For instance, neither work at the end of my 80 pages work sheet in reference. They only work on blank work sheet or very few Given solver previously used or maybe on the limited number of dummy functions/arguments. Further, you are using the Ridder numerical derivative instead of the symbolic derivative. If you take care of not using the Mathcad default ORIGIN 0, many collabs will not even read further. ORIGIN 0 is more natural, there are exceptions. You are not using the plotting facility correctly: collect X's, Y's in vector, in order to reduce the size of the plotting arguments, who cares the corresponding colors ... they are (or should be) all same color = minimum values.

jmG

... jmG

On 10/25/2009 2:23:37 AM, adiaz wrote:
...
>And with more elegance, no way.
>
>Attached, the never well ponderated
>brute force attack.
>
>Regards. Alvaro.
_____________________

More than elegant and functional. Mathcad was not designed brute force, why would you want to brutalize Mathcad ? One more mistake in your sheet. Now works perfect at the the end of my 80 pages. Just too bad it does not work 14.



jmG

... & because individual guesses are assigned,
then no need for constrains in the Given !
Should work on any version < 11.
End of what needs no more consideration or help.

jmG

On 10/25/2009 10:40:56 AM, jmG wrote:
>... & because individual
>guesses are assigned,
>then no need for constrains in
>the Given !
>Should work on any version <<br> >11.
>End of what needs no more
>consideration or help.
>
>jmG
_____________________________

Sorry, YES you need the constrains !

jmG



On 10/25/2009 10:35:10 AM, jmG wrote:
>On 10/25/2009 2:23:37 AM, adiaz wrote:
>...
>>And with more elegance, no way.
>>
>>Attached, the never well ponderated
>>brute force attack.
>>
>>Regards. Alvaro.
>_____________________
>
>More than elegant and functional.
>Mathcad was not designed brute force,
>why would you want to brutalize Mathcad
>? One more mistake in your sheet. Now
>works perfect at the the end of my 80
>pages. Just too bad it does not work 14.

When I talk about elegance, evidently, is not about any brute force routine. Is about the searching and dedication in the Gutman's implementation working at any mathcad version, which don't need unusual definitions of any function.

But even this considerations, there are a little problem remaining: a conceptual one. Why for minimizing a one variable function needs the interval and a guess value? Hard to explain. Probably mathcad routines are very cool, but don't designed for this simple task.

In that sense, my routine needs an additional argument, but is referring to how refine the intervals. Looks the problem as a global searching, while mathcad is based on local properties. As first approach, then, is a very good starting point about minimization problems.

In a practical sense, your procedure is the following: I need to minimize a function, so, to provide a guess value, need to plot the function. But ... to do this, you need eval the function at several points. Actually, so many as the proposal routine needs. This is: my routine eyes as like good as yours. Because there are no guarantee about how f vary, if first procedure works for the entire interval, probably works with refinements.

Actually, proposed routine have theoretical background, and with practical sense. Take a book, search for Bolzano and Weirestrass theorems, and can discover that they are previous of calculus of derivatives. Also can read how a dense set of reals points, like a segment, could be covered by a finite number of intervals. So, to teach about how do this task in practical sense there are not to much tools, even the students know about they, is better ignore them. And yes, I still working in others routines.

There also another big advantage at any routine compared with mathcad ones: user can see how are implemented. Remember that all numerical algorithms fails. Replacement or improvement of the tools is a must, then. There are not definite tools, only a toolbox, and if it is big, better.

You say something also about the use of derivatives, bad use, as you say, because are evaluated in exact form, not numerical. For my is obvious why: because want to compare critical point (the mostly exact that I can) with fmin values. And also you see problems in how I colorize min/max points. I use one color for min, and another for max. Which is the problem with this?

On 10/26/2009 1:49:20 AM, adiaz wrote:
>On 10/25/2009 10:35:10 AM, jmG wrote:
>>On 10/25/2009 2:23:37 AM, adiaz wrote:
>>...
>>>And with more elegance, no way.
>>>
>>>Attached, the never well ponderated
>>>brute force attack.
>>>
>>>Regards. Alvaro.
>>_____________________
>>
>>More than elegant and functional.
>>Mathcad was not designed brute force,
>>why would you want to brutalize Mathcad
>>? One more mistake in your sheet. Now
>>works perfect at the the end of my 80
>>pages. Just too bad it does not work 14.
====================================

>... dedication in the Gutman's implementation working<<br>
==> I don't dispute anything about the simultaneous 2 presentations.
==> My compacted form is just an extension of my work sheet in reference

>But even this considerations, there are a little problem remaining: a conceptual one. Why for minimizing a one variable function needs the interval and a guess value? Hard to explain. Probably Mathcad routines are very cool, but don't designed for this simple task.<<br>
==> Mimize/Maximize need either an interval or a near guess, not both.
==>...with both, it might fail and sometimes the guess is unique and integer number.
==> guess (1) is magic in Mathcad ... some hints in the tutorial 8 Pro.
==> Read more complicated examples in my "Mathcad for Engineers_GivenFind".
==> The Brent method is the source of the complexity.
==> This simple task is piece of cake for Mathcad !

>In that sense, my routine needs an additional argument, but is referring to how refine the intervals. Looks the problem as a global searching, while Mathcad is based on local properties. As first approach, then, is a very good starting point about minimization problems.<<br>
==> Useless routine compared to the Mathcad numerical implementation.
==> .. "local" by the nature of the algo.

>In a practical sense, your procedure is the following: I need to minimize a function, so, to provide a guess value, need to plot the function. But ... to do this, you need eval the function at several points. Actually, so many as the proposal routine needs. This is: my routine eyes as like good as yours. Because there are no guarantee about how f vary, if first procedure works for the entire interval, probably works with refinements.<<br>
==> Your function is too simple, and YES you have to plot ! and sometimes do more !!!
==> Plot Quickplot is enough for the tracking tool and guessing wisely.
==> The routine is stand alone on the corresponding mathematical tool.
==> ... therefore no evaluation needed.
==> how the dummy guess varies: don't care, it's all internal.

>Actually, proposed routine have theoretical background, and with practical sense. Take a book, search for Bolzano and Weirestrass theorems, and can discover that they are previous of calculus of derivatives. Also can read how a dense set of reals points, like a segment, could be covered by a finite number of intervals. So, to teach about how do this task in practical sense there are not to much tools, even the students know about they, is better ignore them. And yes, I still working in others routines.<<br>
==> This particular routine is in "scalar maths", well founded (generally),
==> ... and numerically implemented for purpose in the practical sense
==> with no more maths consideration than "doing right".

>There also another big advantage at any routine compared with Mathcad ones: user can see how are implemented. Remember that all numerical algorithms fails. Replacement or improvement of the tools is a must, then. There are not definite tools, only a toolbox, and if it is big, better<<br>
==> No need to compare conventional and source numerical algorithms as implemented in Mathcad.
==> they have been tested by 1000's of "Grands Savants ",
==> ... and can fail both mathematically & numerically,
==> ... but don't fail by supposed "Mathcad doing wrong".

>You say something also about the use of derivatives, bad use, as you say, because are evaluated in exact form, not numerical. For my is obvious why: because want to compare critical point (the mostly exact that I can) with fmin values. And also you see problems in how I colorize min/max points. I use one color for min, and another for max. Which is the problem with this ? <<br>
==> SORRY COLLAB ! I said nothing about derivatives in this work sheet.
==> Never mind about coloring the plot, do as you want.
==> If you have a scientific application for a very exact value, please let us know to evaluate if it is worth the effort. You have surely at least 12 true decimals that you may not be able to counter-check either ! For more than it is feasible with the Pentium of "Machine Precision 16". you may need to visit some Big Blue.

............................ If you don't feel comfortable with Mathcad and this kind of advanced maths working flawless, then what would the point be reassuring you . Again, how many digits you want. Minimize/Maximize have no symbolic arithmetic in Mathcad/Maple version. If you have access to recent Maple, just check if they have implemented a symbolic Minimize/Maximize, which I'm not aware if it is algebraically possible. e^x is interpreted but is incorrect. What is implemented is exp(x) as explained in the Mathcad 8 Pro.tutorial ... e^x is just a convenient way of writing in book style but not the way to put it in maths (generally).

jmG


" ==> My compacted form is just an extension of my work sheet in reference "

Your form don't looks very compact, defining an usual f(x) as f(Obj,x).

" ==> Mimize/Maximize need either an interval or a near guess, not both. "

Please, explain how.



" ==> Your function is too simple, and YES you have to plot ! and sometimes do more !!! "

Is simple, and? But, actually, don't need any plot. Human intervention is reduced to adjust N, the number of segments to cover the interval.

" ==> Plot Quickplot is enough for the tracking tool and guessing wisely. "

Nice. Let to plot the deflections of a beam, carriying two or three integrals. And make cofee for all in the interval. If you need a plot, is because you need a guess. Also, following with the beam example, changing loads probably needs changing of guess. Better a routine where the problem is driven by a number "N" of iterations, and global for all the worksheet calculations.

" ==> This particular routine is in "scalar maths", well founded (generally), "

I can tell you that there are also something called vectorial maths.

" ==> No need to compare conventional and source numerical algorithms as implemented in Mathcad. "

You don't. Perhaps isn't the case for others. Like me.

" ==> SORRY COLLAB ! I said nothing about derivatives in this work sheet. "

At post 21 you write "Further, you are using the Ridder numerical derivative instead of the symbolic derivative.". That's not true, I optimize the derivative calculus (red asteric appear, then, optimization is done), so, no numerical evaluation involved.

==> Never mind about coloring the plot, do as you want.

At the same post: "... they are (or should be) all same color = minimum values." And of course, I do what I want.

" ==> If you have a scientific application for a very exact value, ... "

Question here isn't precision.

" If you don't feel comfortable with Mathcad and this kind of advanced maths working flawless, then what would the point be reassuring you . "

Flawless? A case that you looks that never considered, sorting different bugs at practical any mathcad version, with working arrounds (two or three) from Gutman and advertising from Jackson? And advanced maths? Only advanced if Borel's lemma is cited. The other things are only at intermediate level.

" Minimize/Maximize have no symbolic arithmetic in Mathcad/Maple version. "

Of course that yes, it have.

" If you have access to recent Maple, just check if they have implemented a symbolic Minimize/Maximize, which I'm not aware if it is algebraically possible. "

MapleVR4 have a symbolic minimize routine. I know that works very well with polynomials, and seems to work with some other structures.

Regards. Alvaro.

Maybe you should clarify your visit and your programme about Maximize/Minimize, it does not converge. Here is supplementary help to read.

.................

>..don't need any plot.Human intervention is reduced to adjust N, the number of segments to cover the interval.<<br> ==> your program diverges ... see the attached
==> your quiz function f(x):=x has no extremum.
==>"The function must have a maximum or minimum." [Mathsoft]
==> 0's are not extremum, just solutions

"It is not possible to define Maximize and Minimize as function calls of any parameters other than the guess values. This limitation will prevent you from iterating through these functions as you would with a Find or Minerr solve block." [Mathsoft]
"The function must have a maximum or minimum." [Mathsoft].

""In mathematics, maxima and minima, known collectively as extrema (singular: extremum), are the largest value (maximum) or smallest value (minimum), that a function takes in a point either within a given neighbourhood (local extremum) or on the function domain in its entirety (global extremum)."" [Wikipedia].

" Minimize/Maximize have no symbolic arithmetic in Mathcad/Maple version. " [jmG]
>Of course that yes, it have.< [Alvaro]
"Optimization problems cannot be solved using the symbolic processor." [Mathsoft].

>Your form don't looks very compact, defining an usual f(x) as f(Obj,x).< [Alvaro]
==> study my reply and the 80 pages "Given/Find" and the Mathsoft examples in the "Advisor newsletter".

Check the convergence of the programme,
also, some functions have no derivative.



jmG

On 10/26/2009 4:10:35 PM, jmG wrote:
>Maybe you should clarify your visit and your programme about Maximize/Minimize, it does not converge.

Formal definitions for left real line are followings:

f left bound iif exist k / for all x in Dom(f) is x < k

m0 = inf(f) iif for all x in Dom(f) is f(x) < m0

m = min(f) iif for all x in Dom(f) is f(x) <= m AND exist xm in Dom(f) / f(xm) = m.

where k and x are reals, inf = infimun (�nfimo in spanish), min = minimun, Dom = Domain, iif = if and only if.

Are properties not of "functions", are better if one see f as what actually it is: f = Co-Domain(f) = {f(x) / x in Dom(f) } ... a set, like Dom(f) also, the set where f is defined.

Reversing inequalities, have definitions for right side, and with abs values, for both.

Waiestrass's theorems (a lot) say that: if A left bounded, then exists m0 inf of f. Another says that if f is continue in [a,b] and left bounded then exists m = min(f) and m = m0 also.

This is the theorem to apply here. Notice that interval must to be closed. f(x) have minimun in [0,1) and it's equal to zero, but have not maximun. In other words: the supreme, which exists and is equal to 1 is not an element of the Co-Domain of f.

There also other big theorems, about compacticity and finite covertures (coberturas in spanish), which giving more background to this method.

Can read more (in spanish) at http://132.248.182.189/Bibliografia/Matematicas/CursosPosgrado/sse/Notas/Metricas%20y%20Topologia.doc

So, this is for give an interval where other methods can be work. Like attached.

Regards. Alvaro.

On 10/26/2009 9:44:14 PM, adiaz wrote:
Bla, bla bla ...

PD: All of this is to remark that this kind of minimization algorithms have not derivatives involved.

Alvaro.

On 10/26/2009 9:47:29 PM, adiaz wrote:
>On 10/26/2009 9:44:14 PM, adiaz wrote:
>PD: All of this is to remark that this
>kind of minimization algorithms have not
>derivatives involved.
>
>Alvaro.
________________________________

Golden ratio has never involved derivatives for centuries. For those interested, here is the original Valery "Golden ratio", adapted by myself. Valery technique was published in the "Advisor news letter". Short, neat, elegant, visible ... no more lemma than itself working.

jmG

Serious debugging for spare time !



jmG

On 10/27/2009 12:19:18 AM, jmG wrote:
>Serious debugging for spare
>time !

On 10/27/2009 12:19:18 AM, jmG wrote:
>Serious debugging for spare
>time !

Actually, the last "bad answer" (-5) is delivered, not casual. f3 have a global min near a and another local min near origin. Golden ratio with parabolic interpolation take this last one, but the answer is "corrected" before emitted, considering the boundaries. What you call Mathcad exact answer is like that because you give the guess as a problem parameter, which is an unwanted situation for me.

Golden search uses the input interval as a guess value, so, changing the interval the answer change. Next step is obvious: make a brute force scan (what people do regarding a plot) and put the answer as the interval for the golden searching.

How to implement this? Discarding intervals by brute force and take one or two (or all!), and refine inside each one? Scan two or three times and then refine with golden ratio and say that the task if finished? This is more than visual plotting procedure. Or vice versa, first golden then confirm? In this way can store functions callings and use a non-equal spaced discretization for scanning. And for each alternative: How many N's is desirable using? All refers to iterations number, but have a very different sense.

Regards. Alvaro.
Announcements

Top Tags