Weird behavior of substitution in Mathematica.
Posted
by Ilya
on Stack Overflow
See other posts from Stack Overflow
or by Ilya
Published on 2010-03-22T02:33:28Z
Indexed on
2010/03/22
2:41 UTC
Read the original article
Hit count: 549
mathematica
|substitution
My question is: why doesn't the following work, and how do I fix it?
Plot[f[t], {t, 0, 2*Pi}] /. {{f -> Sin}, {f -> Cos}}
The result is two blank graphs. By comparison,
DummyFunction[f[t], {t, 0, 2*Pi}] /. {{f -> Sin}, {f -> Cos}}
gives
{DummyFunction[Sin[t], {t, 0, 2 *Pi}], DummyFunction[Cos[t], {t, 0, 2 * Pi}]}
as desired.
This is a simplified version of what I was actually doing. I was very annoyed that, even after figuring out the annoying "right way" of putting the curly brackets nothing works.
In the end, I did the following, which works:
p[f_] := Plot[f[t], {t, 0, 2*Pi}]
p[Sin]
p[Cos]
© Stack Overflow or respective owner