# Manipulate and ListLinePlot

I have the following code:

Mat = DiagonalMatrix @ {α, β, χ};
vec = Diagonal @ Mat;
Manipulate[
ListLinePlot[vec],
{α, 1, 20}, {β, 1, 20}, {χ, 1, 20}
]


but it doesn't work? How can I solve this problem?

• You can move Mat and vec inside or convert them to functions to pass parameter values later. Possible duplicate: mathematica.stackexchange.com/questions/10604/…
– Kuba
Commented Jul 19, 2019 at 11:03
• My original code is more complicated, I can't simply move "{α, β, χ}" in the plot because I have to use "vec" Commented Jul 19, 2019 at 11:09

If you do not want to move the functions inside, then the alternative is to use substitution.

ClearAll[a0, b0, c0];
Mat = DiagonalMatrix[{a0, b0, c0}];
vec = Diagonal[Mat];

Manipulate[
ListLinePlot[vec /. {a0 -> a, b0 -> b, c0 -> c}],
{a, 1, 20},
{b, 1, 20},
{c, 1, 20},
TrackedSymbols :> {a, b, c}
]


This was discussed as Kuba mentioned in the linked to question. It is also a good idea to add TrackedSymbols option all the time.

Mat = DiagonalMatrix @ {α, β, χ};
vec = Diagonal @ Mat;


Initialization + Function + Evaluate

You can define a function v using the option Initialization and use it in the first argument of ListLinePlot:

Manipulate[ListLinePlot[v[α, β, χ]], {α, 1,  20}, {β, 1, 20}, {χ, 1, 20},
Initialization -> {v = Function[{α, β, χ}, Evaluate[vec]]}]


With + Evaluate

You can replace vec with With[{α = α, β = β, χ = χ}, Evaluate @ vec] in the the first argument of ListLinePlot (as an alternative way to force injection of parameter values into vec):

Manipulate[ListLinePlot[With[{α = α, β = β, χ = χ}, Evaluate @ vec]],
{α, 1, 20}, {β, 1, 20}, {χ, 1, 20}]


same picture