# Why this function can't be plot [closed]

### Situation

I have define a function in Mathematica like this:

phi[t_] := Subscript[ϕ, m] Cos[(2 π)/T t]


Then I specify some parameters in this function with a Rule:

flapDragon[t] = phi[t] /. {Subscript[ϕ, m] -> 1.204, T -> 0.0278}


Which output 1.204 Cos[226.014 t].

### Problem

However when I plot the function flapDragon[t] using:

Plot[flapDragon[t], {t, 0, 0.02}]


It plot nothing, but with:

Plot[Evaluate@flapDragon[t], {t, 0, 0.02}]


it can plot something.

### Question

I wonder why I have to use Evaluate before flapDragon[t] with Plot function.

• When you define flapDragon[t] = phi[t] /. etc you need to include an underscore after the t. i.e. You need flapDragon[t_]=phi[t] /. etc. Without the underscore you have only defined flapDragon for the specific symbol t, not anything that might take the place of t. May 25, 2016 at 9:42
• You've not defined the flapDragon function correctly, use fD[t_]:=... Also, avoid using sub and superscript variables. See mathematica.stackexchange.com/questions/18393/… May 25, 2016 at 9:42
• I still wonder why Evaluate works ? May 25, 2016 at 9:53

As others pointed out, you have not defined flapDragon as a function of a variable t, you've defined it as a symbol with a single DownValue for the symbol t.

Notice that this does not work,

Plot[Evaluate@flapDragon[tt], {tt, 0, 0.02}]


That's because flapDragon[tt] is not defined.

I still wonder why Evaluate works

The reason it works is that Plot uses Block to localize its variables. This means that the variable t is not fully localized like it is with Module. Compare these

Block[{t},
flapDragon[t]
]
Module[{t},
flapDragon[t]
]
(* 1.204 Cos[226.014 t] *)
(* flapDragon[t\$502358] *)


So in this case, it works because you use the exact same variable when you defined flapDragon as when you plotted it. You can avoid this confusion by using a pattern to define your function flapDragon[t_] = .... or flapDragon[t_] := .... (both work in this situation)

• En, I still could figure out the reason why Plot[flapDragon[t], {t, 0, 0.02}]  don't works but Plot[Evaluate@flapDragon[t], {t, 0, 0.02}] works from your answer. May 25, 2016 at 14:56
• But, The reason why Plot[Evaluate@flapDragon[t], {t, 0, 0.02}] works may be not because "Plot uses Block to localize its variables" as you figure out. "Plot has Attributes HoldAll, so one possibility to get what you expect is to do just SetOptions[Plot, Evaluated -> True];" Ref. mathematica.stackexchange.com/questions/19453/… May 25, 2016 at 15:01
• That isn't the interesting question at hand, the question is why Plot[Evaluate@flapDragon[t], {t, 0, 0.02}] works at all, when flapDragon wasn't even defined as a function. Of course you need Evaluate when doing Plot, do a search and you'll find many posts about it. The reason it works in this case is most certainly a fluke related to what I wrote here. May 25, 2016 at 15:03
• thanks. it seems you understand my question better than I. I didn't make the essential of my problem clear. I wish to keep my original question as it used to be, for the purpose to remind me of detailed problem formulation May 26, 2016 at 6:39