how to determine coordinate from graph

조회 수: 2 (최근 30일)
Hao Ming Low
Hao Ming Low 2020년 3월 24일
댓글: Star Strider 2020년 3월 24일
i plotted a graph.
>> x = 0:1:20;
>> y = (668.061./x).*[1-exp(-0.1468.*x)]-40;
>> plot(x,y)
And i wanna determine the coordinate of x when y=0. (i want it be labelled on the graph). wht code should i put in?

채택된 답변

Star Strider
Star Strider 2020년 3월 24일
Try this:
x = 0:1:20;
y = (668.061./x).*[1-exp(-0.1468.*x)]-40;
Try this:
x = 0:1:20;
y = (668.061./x).*[1-exp(-0.1468.*x)]-40;
Lv = ~isnan(y); % Avoid ‘NaN’ Values
yq = 0;
xq = interp1(y(Lv), x(Lv), yq); % Interpolate To Find 'x' Value 'xq' Corresponding to 'yq'
figure
plot(x,y)
hold on
plot(xq, 0, 'r+')
hold off
It works here because ‘y’ is monotonic (not oscillating). Other approaches would be necessary otherwise.
  댓글 수: 2
Hao Ming Low
Hao Ming Low 2020년 3월 24일
hi, what if i want to find value of y when x is given? how may i change the code?
Star Strider
Star Strider 2020년 3월 24일
To find the value of ‘y’ for a given ‘x’, create an anonymous function for ‘y’:
yfcn = @(x) (668.061./x).*(1-exp(-0.1468.*x))-40;
so for example:
xq = pi;
y = yfcn(xq)
produces:
y =
38.566778862611955
This also introduces a new way to find ‘xq’:
yq = 0;
xq = fzero(@(v)yfcn(v)-yq, 1)
producing:
xq =
14.799462199459661

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by