Let's first look at what you tried:
If[t=(0||3||5||7), Print[y2]]
Several issues here:
- You don't use
Print
to produce an output. Print
puts things in a special sort of stream, and it's typically used for generating error messages or providing any sort of meta-information (for debugging, for example). So you would just do If[t=(0||3||5||7), y2]
. But the output here would be what y2
evaluates to, which is your entire list (we'll fix this later).
- The expression
t = (0 || 3 || 5 || 7)
is an assignment statement. All you've done here is assign the expression Or[0, 3, 5, 7]
to the symbol t
. If
expects a True
or False
, so this ends up doing nothing at all.
We could keep discussing If
, but this actually isn't the direction you want to take at all. You have a list of things stored in y2
and you want to extract some elements. One way to do that is with Part
(which is usually used in the short form symbol[[index]]
. So, the 5th element of y2
could be fetched like this
y2[[5]]
You can fetch several at the same time by providing a list:
y2[[{5, 6, 7}]]
There's also a fancy iterator-ish notation, but we don't need to bother with that. So, if you knew where your desired plots were (what their position/index was) you could use Part
to fetch them. But you want to get the plots for specific values of t
, so it'd probably be easier to just regenerate those plots with the specific t
values you're interested in:
Table[
Plot[
y[x, t], {x, 0, 10},
AxesLabel -> {"x", "y[x,t]"},
PlotLegends -> StringJoin["t=", ToString[t]]],
{t, {0, 3, 5, 7}}]
Typically, iterators can be given a list of explicit values to use in addition to the normal {iterator, <first>, <last>, <step>}
specification.