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개)

카테고리

도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by