I have a function involving
y=o for x<o;
y=exp(-x)*cos(x) for 0<x<2pi();
y=2*exp(-x)*cos(x) for x>2pi();
please help me to plot such a type of function in xy space

 채택된 답변

VBBV
VBBV 2020년 10월 31일
편집: VBBV 2020년 10월 31일

0 개 추천

%if true
% code
%end
x = -2*pi:0.1:3*pi;
for i = 1:length(x);
if x(i)<0;
y(i)=0;
elseif x(i)<=2*pi & x(i)>=0 ;
y(i) = exp(-x(i))*cos(x(i)*pi/180);
elseif x(i) > 2*pi ;
y(i) = 100*exp(-x(i))*cos(x(i)*pi/180);
end;
end;
plot(x,y)
axis([-2*pi 3*pi -0.2 1])

댓글 수: 3

Sangani Prithvi
Sangani Prithvi 2020년 10월 31일
thank you,
can you pls explain each line briefly in the code. I'm a beginner and trying to learn MATLAB. Thank you
Sangani Prithvi
Sangani Prithvi 2020년 10월 31일
y(i) = 100*exp(-x(i))*cos(x(i)*pi/180
can you please explain why did you mutliply with 100 in the above equation?
you can use a smaller number, say 2, but
y(i) = 2*exp(-x(i))*cos(x(i)*pi/180);
gives a very small step height compared to
y(i) = exp(-x(i))*cos(x(i)*pi/180)
So in the graph it is not noticeable clearly
Thats why i used to 100 which amplifies the step height.
Remember in both cases the step nature does not vary. i,e, decreasing exponential function according to your equations

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

추가 답변 (1개)

Vladimir Sovkov
Vladimir Sovkov 2020년 10월 31일
편집: Vladimir Sovkov 2020년 10월 31일

0 개 추천

syms x;
y=piecewise(x<0,0, 0<=x<2*pi,exp(-x).*cos(x), x>=2*pi,2*exp(-x).*cos(x));
t=linspace(-pi,4*pi,1000);
plot(t,subs(y,x,t));

댓글 수: 2

Sangani Prithvi
Sangani Prithvi 2020년 10월 31일
thank you
Vladimir Sovkov
Vladimir Sovkov 2020년 10월 31일
Welcome.
By the way, in the question, you did not specify what the function is equal to at the boundary points x=0 and x=2*pi; in the code I implied the right limit but you can easily alter this convention.

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

카테고리

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

질문:

2020년 10월 31일

댓글:

2020년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by