2
$\begingroup$

I want to use appropriately use the Manipulate command in conjunction with Plot, to construct animated graphics for the evolution of the solution. I have tried but i could not succed to solve it

$f(x)=y_1(x)+0.2y_4(x)+0.01y_6(x)$.

$y_n$ are the Eigenfunctions that defined as $y_n(x)=\exp\left(\displaystyle{\frac{-x^2}{2}}\right)H_n(x)$


Her[n_] := HermiteH[n, x]
Y[n_] := Exp[-x^2/2]*Her[n]
Y[1]
Y[4]
Y[6]
f[x_] = Y[1] + 0.2 Y[4] + 0.01 Y[6]
```
$\endgroup$
3
  • 2
    $\begingroup$ Your function eigen[n_] is not used anywhere? So why is it there? $\endgroup$
    – Nasser
    Mar 19, 2023 at 17:49
  • $\begingroup$ I have changed it. I have only defined the eigenvalues $\endgroup$ Mar 19, 2023 at 17:55
  • $\begingroup$ Your $f(x)$ is fixed. So it does not change? But you can see how $y_n(x)$ changes with $n$ as shown below. Otherwise you need to clarify how $f(x)$ changes. $\endgroup$
    – Nasser
    Mar 19, 2023 at 18:02

1 Answer 1

3
$\begingroup$

I assume you want to plot $y_n(x)$ as your $f(x)$ does not change? It is always better to pass all the parameters along to all the functions, (i.e. $n,x$) in this example. Do not pass somethings, say $n$, and leave others global (say $x$). This is a recipe for bugs when your program gets larger.

enter image description here

her[x_Symbol, n_Integer] := HermiteH[n, x]
Y[x_Symbol, n_Integer] := Exp[-x^2/2]*her[x, n]
f[x_Symbol, n_Integer] := Y[x, 1] + 2/10* Y[x, 4] + 1/100* Y[x, 6];
Manipulate[
 Module[{x},
  Plot[Evaluate@Y[x, n], {x, 0, 5}, 
   PlotRange -> {Automatic, {-30, 30}}, PlotLabel -> Row[{" Y_", n }],
    PlotStyle -> Red, GridLines -> Automatic, 
   GridLinesStyle -> LightGray]
  ],
 {{n, 0, "n"}, 0, 5, 1, Appearance -> "Labeled"},
 TrackedSymbols :> {n}
 ]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.