how to solve piece-wise function?

1 次查看(过去 30 天)
rising falcon
rising falcon 2015-11-10
f(x)= {1 if x>=0, 0 if x=0, -1 if x<=0
  2 个评论
Guillaume
Guillaume 2015-11-10
Note that your function is ill-defined for x == 0, since it passes all three conditions. You should use strict comparison, < instead of <=.

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2015-11-10
编辑:Guillaume 2015-11-10
That function has a name, it's the signum function, called sign in matlab.
I'm not sure what you mean by solve. The roots of that function is obviously just 0.
  2 个评论
rising falcon
rising falcon 2015-11-10
how to wirte it in matlab?why we use if and end statement to write it in matlab?
Guillaume
Guillaume 2015-11-10
How to write functions and how to use if statement is covered in the Getting Started tutorial in the doc and in million of other tutorials.
function s = mysignum(x)
if x > 0
s = 1;
elseif x < 0
s = -1;
else
s = 0;
end
end

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by