# Why plot returns empty in this example?

Let me rewrite this question, showing the original problem, as it is more subtle than the simple example I showed before using Sin[t]. Here we go again.

When I write this:

foo[$s_,$t_]:=Module[{s=$s,t=$t,r},
r= OutputResponse[TransferFunctionModel[Evaluate[1/(s^2+2*s+1)],s],UnitStep[t],t];
Plot[Chop@First@r,{t,0,20}]
];
foo[s, t]


I get an empty plot. But when I write this

foo[s_,t_]:=Module[{r},
r= Chop@First@OutputResponse[TransferFunctionModel[1/(s^2+2*s+1),s],UnitStep[t],t];
Plot[r,{t,0,20}]
];
foo[s, t]


I do not get an empty plot.

My question is: Why first example above does not produce a plot?

I know it has to do with how 's' and 't', the free parameters, to the calls to TransferFunctionModel[] and OutputResponse[]. But I do not see exactly why that is.

thanks,

-
It's good to see you are back, Nasser. –  Leonid Shifrin Apr 17 '12 at 9:05

In your first example, the Plot is inside a Module that localizes t into something like t$23. So, when you run foo[s, t], you are actually running something similar to  t$23=t;
r=E^-t$23 UnitStep[t$23];
Plot[Chop@First@r,{t$23,0,20}]  The second line returns an expression of t. When you insert it in the last Plot, it doesn't run properly, because, the {t$23, ...} argument in Plot is held, it doesn't evaluate to t before plotting.

In the second example, however, you don't have this problem. r becomes an expression of whatever variable p you call in foo[s, p] (t in this case), and that's the same variable you are using in your Plot. Even if Plot holds its arguments, so it's "immune to evaluation", it's not immune to the lexical replacement Module does.

First example analogy:

Module[{x = x2},
{x, Hold[x]}]

{x2, Hold[x\$14454]}


Second example analogy:

Module[{},
{x, Hold[x]}]

{x, Hold[x]}

-
@NasserM.Abbasi, edited. See if it's clearer now –  Rojo Apr 17 '12 at 10:13