How can i define piecewise function ?

4 views (last 30 days)
Fatih
Fatih on 22 Feb 2014
Answered: Andreas Sorgatz on 25 Aug 2017
I want to define a piecewise function
syms x y piecewise([x<=y,1+y],[x>y,1+x])
but i get error message
Undefined function 'piecewise' for input arguments of type 'sym'.
How can i define this function ?

Answers (1)

Andreas Sorgatz
Andreas Sorgatz on 25 Aug 2017
You are mixing MATLAB and MuPAD syntax. Also ';' or a linefeed is missing. Try
>> syms x y
>> piecewise(x<=y,1+y, x>y,1+x)
ans =
piecewise(x <= y, y + 1, y < x, x + 1)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!