如何在mathematica中绘制区间值函数?
考虑以下定义:
f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],x==1/2},{1,x>1 /2}}];
然后,当对函数进行 Plot[f[x],{x,0,1}]
时,图表不会描绘区间值图表的 f[1/2]
。
任何关于如何在 Mathematica 中绘制区间值函数的想法将不胜感激。
更新 #1:我发现了一个 hack:
Plot[ f[x], {x,0,1}, ExclusionsStyle->Opacity[1]];
然而,这个 hack 并没有研究一般的区间值函数,例如
f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],1/2<=x<=1}}];
即问题的本质。
更新#2:
作为下面 @Heike 的简洁示例的后续:这只是部分解决方案。如果尝试以下操作:
f[x_] = Piecewise[{{0, x <; 1/2}, {间隔[{x, 1}], 1/2 <= x <= 1}}];
绘制[ {f[x] /.间隔[a_]:> a[[1]],f[x]/。间隔[a_]:>一个[[2]]},
{x, 0, 1},填充-> {1-> {2}}]
那么图表描绘了 x=1/2 处的一段,该段等于值 [0,1] 而不是 [1/2,1]。
Consider the following definition:
f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],x==1/2},{1,x>1/2}}];
Then when one does the Plot[f[x],{x,0,1}]
of the function, the graph does not depict the interval value f[1/2]
of the graph.
Any ideas on how to plot interval-valued functions in Mathematica would be much appreciated.
Update #1: I've found a hack:
Plot[ f[x], {x,0,1}, ExclusionsStyle->Opacity[1]];
The hack, however, does not work on a general interval-valued function, such as
f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],1/2<=x<=1}}];
which is the essence of the question.
Update #2:
As a followup to the neat example of @Heike below: it's only a partial solution. For if one tries the following:
f[x_] = Piecewise[{{0, x < 1/2}, {Interval[{x, 1}], 1/2 <= x <= 1}}];
Plot[ {f[x] /. Interval[a_] :> a[[1]], f[x] /. Interval[a_] :> a[[2]]},
{x, 0, 1}, Filling -> {1 -> {2}}]
then the graph depicts a segment at x=1/2 that is equal to the value [0,1] instead of [1/2,1].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以做类似
的事情
Maybe you could do something like