How to plot varying cos function

조회 수: 2 (최근 30일)
Assiya Syzdykova
Assiya Syzdykova 2020년 10월 17일
댓글: Ameer Hamza 2020년 10월 18일
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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 17일
편집: Ameer Hamza 2020년 10월 17일
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
Assiya Syzdykova
Assiya Syzdykova 2020년 10월 17일
Amazing! Thanks
Ameer Hamza
Ameer Hamza 2020년 10월 18일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by