sin function gives straight line when plotting

15 views (last 30 days)
Akasha Sage
Akasha Sage on 27 Feb 2019
Answered: VBBV on 29 Nov 2021
when plotting
x = [0 50];
y1 = 0.25*x.*sin(x);
y2 = 0.25*x;
y3 = -0.25*x;
plot(x,y1,x,y2,'--',x,y3,'--')
i get a straight line for y1, it should be oscillating between y2 and y3. what am i doing wrong?

Answers (2)

Star Strider
Star Strider on 27 Feb 2019
You are only plotting two points, at x=0 and x=50.
Try this instead:
x = linspace(0, 50);
y1 = 0.25*x.*sin(x);
y2 = 0.25*x;
y3 = -0.25*x;
plot(x,y1,x,y2,'--',x,y3,'--')

VBBV
VBBV on 29 Nov 2021
x = [0:0.1:50];
y1 = 0.25*x.*sin(x);
y2 = 0.25*x;
y3 = -0.25*x;
plot(x,y1,x,y2,'--',x,y3,'--')

Community Treasure Hunt

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

Start Hunting!