4
$\begingroup$

Code

 y[1] = 1;
 y[2] = 2;
 y[3] = 3;
 Min[y[1], y[2], y[3]]

Outputs "1", but desired result is y[1]

How to do that? Many thanks for help.

$\endgroup$
5
$\begingroup$

You can get the value(s) i for which y[i] is minimal :

 y[1] = 10;
 y[2] = 20;
 y[3] = 30;
 MinimalBy[Range[3],y]

{1}

But as soon as you wrap the result 1 in y[...], y[1] will be evaluated to 10, accordingly to the princips of Mathematica.

$\endgroup$
  • $\begingroup$ HoldForm[y[n]] /. n -> First@MinimalBy[Range[3], y] gives y[1] $\endgroup$ – bbgodfrey Jul 29 '17 at 3:01
  • $\begingroup$ @bbgodfrey Your answer help me a lot. Many thanks. $\endgroup$ – Robin_Lyn Jul 29 '17 at 3:20
3
$\begingroup$

For the exact example given you could perhaps utilize the DownValues list:

MinimalBy[DownValues[y], Last][[1, 1]]
HoldPattern[y[1]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.