如何在mathematica中绘制区间值函数?

发布于 2024-12-19 04:19:10 字数 780 浏览 0 评论 0原文

考虑以下定义:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2024-12-26 04:19:11

也许你可以做类似

f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],1/2<=x<=1}}];

Plot[{f[x] /. Interval[a_] :> a[[1]], 
 f[x] /. Interval[a_] :> a[[2]]}, {x, 0, 1}, Filling -> {1 -> {2}}]

plotting an Interval的事情

Maybe you could do something like

f[x_]=Piecewise[{{0,x<1/2},{Interval[{0,1}],1/2<=x<=1}}];

Plot[{f[x] /. Interval[a_] :> a[[1]], 
 f[x] /. Interval[a_] :> a[[2]]}, {x, 0, 1}, Filling -> {1 -> {2}}]

plotting an interval

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文