2

我正在尝试在 Mathematica 中绘制缓和函数的导数。它可以区分函数,并且可以使用 绘制函数%,但我希望能够通过将导数分配为函数来绘制f[t_],然后Plot[ f[t] , {t,-1,1} ]

我不确定如何解决出现的错误。

Mathematica 代码是:

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 *)
4

3 回答 3

6

尝试使用Plot[Evaluate[f[t]], {t, -1, 1}]

当涉及到用户定义的函数时,Plot 有点挑剔。

于 2012-12-05T12:27:53.750 回答
2

使用给定的功能,您可以使用:

Plot[f[t], {t, -1, 1}, Evaluated -> True]

Evaluated -> True优先Evaluate[f[t]].

更好的是遵循 nikie 的建议并以f不同的方式定义:

Block[{t},
  f[t_] = D[moll[t], t]
]

有关解释,请参阅分配导数中的范围界定。

于 2012-12-08T12:45:32.210 回答
1

Plot 的“挑剔”来自它的Atttributes[Plot],其中包括HoldAll,因此朴素的f永远不会被评估。如ratatosk建议的力评估。

于 2012-12-06T13:41:32.973 回答