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!