Plot[2*x^2 - x + 2, {x, -1, 1}]
plots a function of x from -1 to 1. As far as I can see, I cannot "save" this range in a variable:
u = {x, -1, 1};
Plot[2*x^2 - x + 2, u]
Generates Plot::pllim: Range specification u is not of the form {x, xmin, xmax}.
Hopefully my intention is obvious, what is the most concise way of accomplishing it?
Because someone will wonder why I could possibly want to do this: I have
NDSolve[..., ..., {t, 0, 100}];
Plot[..., {t, 0, 100}];
I don't want to need to modify both 100's as my desired range changes. Yes, I could use variables t0 and t1, but is what type is the range/domain expression? Why can't I store it directly?
x
has a value). Unfortunately I see no convenient way to get around this. As MrW pointed it out,Plot[..., Evaluate[u]]
is not robust: it won't work ifx
has a value. Yes, this is annoying, and I'd also like a really convenient way to store these ranges. $\endgroup$With[{lims = Sequence[0, 100]}, NDSolve[...,..., {x, ##}] &@lims; Plot[..., {x, ##}] &@lims ]
$\endgroup$u
and that it wouldn't do any harm to re-specify the variablex
explicitly inPlot
. So why notu={-1,1}; Plot[f[x], Evaluate@Prepend[u,x]]
? Or is it important thatx
be referenced withinu
itself? If so, why? $\endgroup$