1

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?

kglr
  • 394,356
  • 18
  • 477
  • 896
Gae P
  • 637
  • 3
  • 11
  • 2
    You can move Mat and vec inside 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
  • My original code is more complicated, I can't simply move "{α, β, χ}" in the plot because I have to use "vec" – Gae P Jul 19 '19 at 11:09

2 Answers2

1

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.

Nasser
  • 143,286
  • 11
  • 154
  • 359
1
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]]}] 

enter image description here

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

kglr
  • 394,356
  • 18
  • 477
  • 896