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!