How to plot step functions in Matlab
Show older comments
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
Accepted Answer
More Answers (1)
Vladimir Sovkov
on 31 Oct 2020
Edited: Vladimir Sovkov
on 31 Oct 2020
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 Comments
Sangani Prithvi
on 31 Oct 2020
Vladimir Sovkov
on 31 Oct 2020
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.
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!