# Why is ww[[1]] not a valid variable in FindMinValue and Plot [closed]

Why is ww[[1]] not a valid variable when given to FindMinValue and Plot, but is a variable in Minimize? How can I fix the problem?

In:
ww = Table[w[i], {i, 1, 6}];
a1[y1_, x_] = Function[#1*Cos[#1*0.1] + #2*2][y1, x];

Minimize[a1[ww[[1]], 3], ww[[1]]]
FindMinValue[a1[ww[[1]], 3], {ww[[1]], 1}]
Plot[a1[ww[[1]], 3], {ww[[1]], 0, 1}]

Out:
{0.389037, {w[1] -> -8.60334}}

FindMinValue::vloc: The variable ww[[1]] cannot be localized so that it can
be assigned to numerical values. >>

FindMinValue[a1[ww[[1]], 3], {ww[[1]], 1}]

Plot::write: Tag Part in ww[[1]] is Protected. >>

Plot[a1[ww[[1]], 3], {ww[[1]], 0, 1}]

• Plot has the attribute HoldAll, but you may enforce evaluation with Evaluate: Plot[Evaluate[a1[ww[[1]], 3]], Evaluate[{ww[[1]], 0, 1}]]. Similarly, you may use FindMinValue[a1[ww[[1]], 3], Evaluate@{ww[[1]], 1}]. – Henrik Schumacher Feb 4 at 18:47
• Thanks a lots. But it is not uncomfortable to use "Evaluate" all time. Maybe is there other way how make function with different amount of variables defined by array ? – ILIa Feb 5 at 8:37

This is not so much an answer as some advice on how you can avoid all the issues that are causing you problems by getting rid of unnecessary complications in your code. You will do better by abandoning the array ww and Function.

a1[y_, x_] := y Cos[.1 y] + 2 x
min = Minimize[a1[w[1], 3], w[1]]


{0.389037, {w[1] -> -8.60334}}

FindMinValue[a1[w[1], 3], {w[1], -1}]


0.389037

To make a plot showing the minimum, extract the coordinates of the minimum

minPt = {min[[2, 1, 2]], min[[1]]}


{-8.60334, 0.389037}

and add it to a plot of a with Epilog.

Plot[a1[w[1], 3], {w[1], -15, 1},
Epilog -> {Red, AbsolutePointSize[5], Point[minPt]}]


• Thanks. But my general goal is to learn how make function with different amount of variables defined by array (Table). – ILIa Feb 5 at 8:25
• @ILIa. In general you don't have make indexed variables with Table, you can just refer to as I did in the code above and there will be automatically created. If for some strange reason you really do have make them, Do is better than Table – m_goldberg Feb 5 at 18:23