【问题标题】:Mathematica: Use Piecewise instead of IfMathematica:使用分段而不是 If
【发布时间】:2012-04-29 18:51:47
【问题描述】:

我通过“If”有这个周期性定义的函数:

T = 1;

Tt[t_] := Quotient[t, T]*T
f[t_] := If[t >= Tt[t] && t < ((Tt[t] + T/2)), 1, -1]

我需要用“Piecewise”重新定义它。我的尝试如下所示:

g[t_] := Piecewise[{
        {1, (t >= Tt[t] && t < ((Tt[t] + T/2)))}
    },
    -1
];

如果我绘制 f[t],我会得到这个完美的周期图。 如果我绘制 g[t],我会在 y=1 处得到一条虚线,在 y=-1 处得到另一条虚线(移至另一条)。

看起来mathematica 正确绘制了函数的各个部分,但没有连接这些部分。

【问题讨论】:

  • 如果您还有其他问题,这里的大多数专家都已转至Mathematica

标签: function if-statement wolfram-mathematica plot piecewise


【解决方案1】:

你可以使用:

Plot[{g[t]},{t,-5,5}, Exclusions->None]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多