How to plot varying cos function

4 vues (au cours des 30 derniers jours)
Assiya Syzdykova
Assiya Syzdykova le 17 Oct 2020
Commenté : Ameer Hamza le 18 Oct 2020
I have to draw a function like below
I need a cos function when its is between pi and 2*pi, and 0 function when it is between 0 and pi. Also I am trying to plot it for several periods:
syms t
T=1/(n/60)
if pi<=5*pi*t<=2*pi
Qt = 0.001*cos(5*pi*t)
if 0<5*pi*t<pi
Qt=0
end
plot(t,Qt,[0, 5*T])
Could someone help me to fix this code, please

Réponse acceptée

Ameer Hamza
Ameer Hamza le 17 Oct 2020
Modifié(e) : Ameer Hamza le 17 Oct 2020
Try something like this
t = linspace(0, 4*pi, 200);
y = cos(t);
y(y<0) = 0;
plot(t, y)
xlim([0 4*pi]);
ylim([-1.5 1.5]);
  2 commentaires
Assiya Syzdykova
Assiya Syzdykova le 17 Oct 2020
Amazing! Thanks
Ameer Hamza
Ameer Hamza le 18 Oct 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by