How to find the value of x when y = 0 and label on the curve?

조회 수: 33 (최근 30일)
LIM MING HUI
LIM MING HUI 2022년 4월 11일
댓글: Star Strider 2022년 4월 12일
Hello,
I'm trying to find and label the coordinate of (x,y) when y=0 but I don't succeed.
x = 0:0.01:66.03;
y=(3.7*(10*(x/66.03).^3-15*(x/66.03).^4+6*(x/66.03).^5)-1.86);
plot(x,y,'c-','LineWidth',3);
Thank you in advance for you help...

채택된 답변

Star Strider
Star Strider 2022년 4월 11일
Using interp1
x = 0:0.01:66.03;
y=(3.7*(10*(x/66.03).^3-15*(x/66.03).^4+6*(x/66.03).^5)-1.86);
x_at_y0 = interp1(y,x,0)
x_at_y0 = 33.1102
figure
plot(x,y,'c-','LineWidth',3);
hold on
plot(x_at_y0, 0, 'r+', 'MarkerSize',15)
hold off
text(x_at_y0, 0, sprintf(' \\leftarrow (%.2f, %.2f)',x_at_y0,0), 'Horiz','left', 'Vert','middle')
.

추가 답변 (1개)

KSSV
KSSV 2022년 4월 11일
x = 0:0.01:66.03;
y=(3.7*(10*(x/66.03).^3-15*(x/66.03).^4+6*(x/66.03).^5)-1.86);
[val,idx] = min(abs(y)) ;
plot(x,y,'c-','LineWidth',3);
hold on
plot(x(idx),y(idx),'*r')
  댓글 수: 2
LIM MING HUI
LIM MING HUI 2022년 4월 11일
But this show the y=-0.00993621... My target is to get x when y=0...
KSSV
KSSV 2022년 4월 11일
fun = @(x) (3.7*(10*(x/66.03).^3-15*(x/66.03).^4+6*(x/66.03).^5)-1.86);
x0 = fzero(@(x) fun(x), 33)
x0 = 33.1102
fun(x0)
ans = 2.2204e-16

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by