Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'How can one embed FindMinimum as part of a function?' topicStudent Support Forum > General > Archives > "How can one embed FindMinimum as part of a function?"

Help | Reply To Topic
Author Comment/Response
Tom McKendree
01/29/00 06:14am

How can I use FindMinimum in the middle of an expression, so that I can extract the input value at which the function is [locally] minimized, and then explicitly continue to use that input value in the larger expression? In particular, I need to do this with SetDelayed.

Below are several different approaches which do not work, although at least some of them look like they should. This particular example can be implemented by ignoring the input value, and just taking the optimized output (the last version, which, for some reason, does work), but the idea is very important. For example, I would like to find the value of v that minimizes hprunitcost, test that value to see if it meets other constraints, and then use that value if it meets the constraints (and otherwise use a differently derived v).



Thank you,

Tom McKendree
tmckendree@west.raytheon.com

      *      *      *      *      *



Notebook[{

Cell[CellGroupData[{
Cell[''\<\
Examples for Question About Using FindMinimum As Part of a Normal \
SetDelayed Function\
\>'', ''Subsection''],

Cell[TextData[{
''The purpose, of course, is to be able to define functions, have functions \
call other functions, and have everything work the way it normally does in '',
StyleBox[''Mathematica'',
FontSlant->''Italic''],
'', all while using FindMinimum as part of the functions, and being able to \
extract out the input parameter value at which FindMinimum finds the local \
minimum on the questioned function, as an output for further calculation.''
}], ''Text''],

Cell[CellGroupData[{

Cell[''Definitions for Functions Used Below'', ''Subsubsection''],

Cell[BoxData[
\(hprunitcost[gm_, ra_, rb_, v_, cp_, cf_, v0_, i_] :=
cp\[Times]i\[Times]\(ra + rb\)\/v +
cf\/\(2\ \[Pi]\)\
\[Times]NIntegrate[
\(-1\) +
Re[\[ExponentialE]^
\((\(1\/v0\)
\((\@\(gm\/rb + v\^2 -
2\ \@\(gm\/rb\)\ v\
Sin[Arg[E\^\(\(-I\)\ \[Theta]\)\ ra - rb]]
\) + \[Sqrt]\((
gm\/ra + v\^2 -
2\ \@\(gm\/ra\)\ v\
Sin[Arg[\(-ra\) + E\^\(I\ \[Theta]\)\ rb]])
\))\))\)], {\[Theta], 0, 2\ \[Pi]}]\)],
''Input''],

Cell[BoxData[
\(hprtrivialunitcost[ra_, rb_, v_, cp_, cf_, v0_, i_] :=
cp\[Times]i\[Times]\(ra + rb\)\/v +
cf*\((\[ExponentialE]\^\(2\ v/v0\) - 1)\)\)], ''Input'']
}, Closed]],

Cell[CellGroupData[{

Cell[''Approaches That Don't Work'', ''Subsubsection''],

Cell[''\<\
These approaches do not work, although several of them seem to \
follow syntax that does work for more \''normal\'' functions than \
FindMinimum.\
\>'', ''Text''],

Cell[BoxData[
\(FindMinimum[
hprunitcost[gm, ra, rb, v, cp, cf, v0, i], {v,
hprtrivialunitcost[ra, rb, v, cp, cf, v0, i],
1.02\[Times]hprtrivialunitcost[ra, rb, v, cp, cf, v0, i]}]\)],
''Input''],

Cell[BoxData[
\(hprcost[gm_, ra_, rb_, cp_, cf_, v0_, i_, \[Lambda]_] :=
If[ra == rb, 0,
\[Lambda]\[Times]hprunitcost[gm, ra, rb,
\((v\ \ /.
\((\(FindMinimum[
hprunitcost[gm, ra, rb, v, cp, cf, v0, i], {v,
Evaluate[
cf\ \((\(-1\) + E\^\(\(2\ v\)\/v0\))\) +
\(cp\ i\ \((ra + rb)\)\)\/v],
Evaluate[
1.02\[Times]\((
cf\ \((\(-1\) + E\^\(\(2\ v\)\/v0\))\) +
\(cp\ i\ \((ra + rb)\)\)\/v)\)]}]
\)\[LeftDoubleBracket]2, 1\[RightDoubleBracket])\))\),
cinv, cf, v0, i]]\)], ''Input''],

Cell[BoxData[
\(hprcost[gm_, ra_, rb_, cp_, cf_, v0_, i_, \[Lambda]_] :=
If[ra == rb, 0,
\[Lambda]\[Times]\((
\(FindMinimum[
hprunitcost[gm, ra, rb, v, cp, cf, v0, i], {v,
Evaluate[
cf\ \((\(-1\) + E\^\(\(2\ v\)\/v0\))\) +
\(cp\ i\ \((ra + rb)\)\)\/v],
Evaluate[
1.02\[Times]\((
cf\ \((\(-1\) + E\^\(\(2\ v\)\/v0\))\) +
\(cp\ i\ \((ra + rb)\)\)\/v)\)]}]
\)\[LeftDoubleBracket]1\[RightDoubleBracket])\)]\)],
''Input''],

Cell[BoxData[
\(hprcost[gm_, ra_, rb_, cp_, cf_, v0_, i_, \[Lambda]_] :=
\((vlow =
cf\ \((\(-1\) + E\^\(\(2\ v\)\/v0\))\) +
\(cp\ i\ \((ra + rb)\)\)\/v; vhigh = 1.02\[Times]vlow;
vfind = FindMinimum[
hprunitcost[gm, ra, rb, v, cp, cf, v0, i], {v, vlow, vhigh}];
vrule = vfind\[LeftDoubleBracket]2, 1\[RightDoubleBracket];
vuse = \((v\ /. \ vrule)\);
\[Lambda]\[Times]hprunitcost[gm, ra, rb, vuse, cp, cf, v0, i])\)\)],
''Input''],

Cell[BoxData[
\(hprcost[gm_, ra_, rb_, cp_, cf_, v0_, i_, \[Lambda]_] :=
If[ra == rb, 0,
\[Lambda]\[Times]hprunitcost[gm, ra, rb,
\((v\ \ /.
\((\(FindMinimum[
Evaluate[hprunitcost[gm, ra, rb, v, cp, cf, v0, i]], {
v, 50000, 52000}]\)\[LeftDoubleBracket]2, 1
\[RightDoubleBracket])\))\), cp, cf, v0, i]]\)], ''Input'']
}, Open ]]
}, Open ]]
},
FrontEndVersion->''Macintosh 3.0'',
ScreenRectangle->{{0, 832}, {0, 604}},
WindowSize->{503, 565},
WindowMargins->{{11, Automatic}, {Automatic, 5}},
MacintoshSystemPageSetup->''\<\
00@0001804P000000]/2@?oWonh2o`9B7`<5:0?l0040004/0B`000002nL9H04/
02d5X5k/02H40@4101P00BL?00400@0000000000000000010000000000000000
00000000000000000000004000910000\>''
]



URL: ,
Help | Reply To Topic