How to draw a discontinue function

Hi all, I have x(t) = cos(t) and y(t) = 0.5 if abs(x(t)) larger than 0.5, other wise y(t) = x (t). I have no idea how to plot y(t). Please help me!!!

 Réponse acceptée

Wayne King
Wayne King le 3 Juin 2012

0 votes

t = 0:0.01:2*pi;
x = cos(t);
y = x;
y(abs(x)>0.5) = 0.5;
% to see the discontinuity
stem(t(1:400),y(1:400))
If you really want to see the discontinuity most clearly, it's probably a good idea to delete the baseline in the stem plot.
h = stem(t(150:250),y(150:250),'markerfacecolor',[0 0 1]);
axis tight;
delete(get(h,'baseline'))

2 commentaires

UCLA
UCLA le 3 Juin 2012
Thank you for your answer. But I am not sure about your notation y(abs(x)>0.5) does that mean y is a function and abs(x)>0.5 is the argument? Can I say if abs(x)>0.5 y = 0.5 instead? Thanks!
Wayne King
Wayne King le 3 Juin 2012
that is logical indexing, it says for all the elements where the absolute value of x is greater than 0.5, set the corresponding y element to 0.5. That is the definition you gave. I think logical indexing is the easiest way to do it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by