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?
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?
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
Matandvecinside or convert them to functions to pass parameter values later. Possible duplicate: https://mathematica.stackexchange.com/questions/10604/how-are-parameters-evaluated-for-a-plot-in-manipulate – Kuba Jul 19 '19 at 11:03