How to add markers to a plot after using fzero
1 次查看(过去 30 天)
显示 更早的评论
I am working on making a plot of y vs y'. I have constructed the plot and used the fzero function initialized at -4, -2, 0, 2, 4 to find all zeros of y'. I am trying to add these zeros to the plot already made as markers. Thanks for your help!
x=-2*pi : 2*pi;
y=3*x.*sin(x)-2*x;
y1=3*sin(x)+3*x.*cos(x)-2;
plot(x,y,'-',x,y1, '--')
xlabel('\bf\itx-axis\rm')
ylabel('\bf\ity-axis\rm')
legend('y=3xsin(x)-2x','y1=3sin(x)+3xcos(x)-2', 'Location', 'S')
x0 =-4; x1=-2; x2=0; x3=2; x4=4;
z0 = fzero('3*sin(x)+3*x.*cos(x)-2', x0)
z1 = fzero('3*sin(x)+3*x.*cos(x)-2', x1)
z2 = fzero('3*sin(x)+3*x.*cos(x)-2', x2)
z3 = fzero('3*sin(x)+3*x.*cos(x)-2', x3)
z4 = fzero('3*sin(x)+3*x.*cos(x)-2', x4)
0 个评论
采纳的回答
Star Strider
2017-10-26
I would use a loop to create a vector for ‘z’:
x=-2*pi : 2*pi;
y=3*x.*sin(x)-2*x;
y1=3*sin(x)+3*x.*cos(x)-2;
x0 = [-4, -2, 0, 2, 4];
for k1 = 1:numel(x0)
z(k1) = fzero('3*sin(x)+3*x.*cos(x)-2', x0(k1));
end
figure
plot(x,y,'-',x,y1, '--')
hold on
plot(z, zeros(size(z)), 'pg')
hold off
xlabel('\bf\itx-axis\rm')
ylabel('\bf\ity-axis\rm')
legend('y=3xsin(x)-2x','y1=3sin(x)+3xcos(x)-2', 'Location', 'S')
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Change Markers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!