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!

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mayo de 2012

0 votos

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 comentarios

goal24
goal24 el 28 de Mayo de 2012
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 el 29 de Mayo de 2012
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 el 29 de Mayo de 2012
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 el 29 de Mayo de 2012
Okay I got it!! Thanks for the help!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by