MATLAB 无法识别分段函数

Piecewise function not recognised by MATLAB

我正在尝试使用符号变量 x 设置符号表达式 V,例如:

V = piecewise(x<=0.5, 2*x, x>0.5, 2-2*x)

但是 MATLAB 甚至无法识别此命令,尽管在其文档中有所提及。

一直返回的错误是:

Undefined function or variable 'piecewise'.

我在网上搜索了这个错误信息,不断弹出MuPad Notebook之类的名字,但我也不知道是什么意思。我有 Symbolic Math Toolbox(我使用 which privResolveArgs 检查过)。 最后,如果有帮助,我将使用 MATLAB 2016a。

提前感谢大家的帮助。

piecewise 函数从 MATLAB 版本 2016b 开始可用。在 2016a 中,您必须使用函数 heaviside:

syms y(x)
y(x)= heaviside(x-0.5)*(2-2*x)+heaviside(0.5-x)*2*x