How can i define piecewise function ?

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 ?

回答 (1 件)

Andreas Sorgatz
Andreas Sorgatz 2017 年 8 月 25 日

0 投票

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)

カテゴリ

タグ

質問済み:

2014 年 2 月 22 日

回答済み:

2017 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by