how to determine coordinate from graph

4 views (last 30 days)
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?

Accepted Answer

Star Strider
Star Strider on 24 Mar 2020
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 Comments
Hao Ming Low
Hao Ming Low on 24 Mar 2020
hi, what if i want to find value of y when x is given? how may i change the code?
Star Strider
Star Strider on 24 Mar 2020
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

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!