简体   繁体   中英

Piecewise function not recognised by MATLAB

Im trying to set up a symbolic expression V using the symbolic variable x like:

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

However MATLAB doesn't even recognise this command although it is mentioned in their documentation.

The error it keeps returning is:

Undefined function or variable 'piecewise'.

I searched online for this error message, and some names like MuPad Notebook kept popping up, but I don't know what those mean either. I do have the Symbolic Math Toolbox ( I checked using which privResolveArgs ). Finally, Im using MATLAB 2016a if that helps.

Thanks for all the help, in advance.

The piecewise function is available starting from MATLAB version 2016b. In 2016a you have to use the function heaviside :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM