I'm trying to plot the derivative of a mollifier function in Mathematica. It differentiates the function OK, and can plot the function using %
, but I would like to be able to plot by assigning the derivative to be a function f[t_]
, then Plot[ f[t] , {t,-1,1} ]
.
I'm not sure how to solve the error that comes up.
The Mathematica code is:
Clear[moll, f]
moll[x_] :=
Piecewise[ { {E^(-1/(1 - x^2)), -1 < x < 1} , {0,x <= -1 || x >= 1} } ]; (* Standard mollifier *)
f[t_] := D[ moll[t] , t]
f[t]
Plot[%, {t, -1, 1}] (* this line works *)
Plot[f[t], {t, -1, 1}] (* this line comes up with an error *)
Try using Plot[Evaluate[f[t]], {t, -1, 1}]
Plot is a bit picky when it comes to user defined functions.