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 件のコメント

goal24
goal24 2012 年 5 月 28 日
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.
goal24
goal24 2012 年 5 月 29 日
oh there was a typo all the x should be t as its a function of m(t). But still having error. Any suggestions?
Walter Roberson
Walter Roberson 2012 年 5 月 29 日
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.
goal24
goal24 2012 年 5 月 29 日
Okay I got it!! Thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by