[討論] 區間函數寫法

作者: vacuous (痾)   2019-02-27 11:35:28
https://i.imgur.com/Z6VKfgR.jpg
如上圖的函數
x<1 -> y=x
x>=1 -> y=1
請問要用什麼方式才能表示出y
並可以得到任意x所對應的y
謝謝
作者: shuncheng (shuncheng)   2019-02-27 13:54:00
假定x變數已存在 y = (x>=1)+(x<1)*x
作者: profyang (prof)   2019-02-28 22:53:00
上的寫法好精煉 我居然無言以對 不過要注意這種函數有時可會需要用到x<0的情況 就要寫的複雜一些吧 應該多一項阿 不過你的後面應該要用(x<1).*x另外x<0通常可能是y=0, 所以y=(x>=1)+(x<1 & x>=0).*x
作者: shuncheng (shuncheng)   2019-03-01 00:32:00
歐歐歐 感謝指正

Links booklink

Contact Us: admin [ a t ] ucptt.com