Plotting Discontinuous Function

Hi, I have a question about plotting a discontinuous function. My function m1(t) = 1 when m(t) greater or equal to 0 and -1 when m(t) is less than 0, where m(t) = cos(t). I have an idea of what the graph needs to look like changing level planes 1 and -1 every [-pi/2, pi/2] but have no idea how to implement it. Please help!

 采纳的回答

Walter Roberson
Walter Roberson 2012-5-28

0 个投票

Draw it continuous segment by continuous segment, OR put a NaN between the continuous parts. Or just let it connect the discontinuous parts.
Have you considered a stairs plot?

4 个评论

Yah I was thinking of some sort of stairs plot, like a unit step function. I have tried this code but I keep coming up with an error:
t = 0:0.05:10;
m = (1) .* (x < pi/2) + (-1) .* (pi/2 < x & x < 3*pi/2 ) + (1 ) .* (3*pi/2 < x & x < 5*pi/2) + (-1) .* (x < 5*pi/2 & x< = 7*pi/2);
I am not sure though, I'm fairly new to this.
oh there was a typo all the x should be t as its a function of m(t). But still having error. Any suggestions?
You have < = with a space between the two. You need to fix that.
You have a more subtle bug. In one of your conditions, you have _two_ checks to see if x is less than a particular value.
Okay I got it!! Thanks for the help!

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by