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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityCode
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.
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.
For the exact example given you could perhaps utilize the DownValues
list:
MinimalBy[DownValues[y], Last][[1, 1]]
HoldPattern[y[1]]