how to determine coordinate from graph

3 Ansichten (letzte 30 Tage)
Hao Ming Low
Hao Ming Low am 24 Mär. 2020
Kommentiert: Star Strider am 24 Mär. 2020
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?

Akzeptierte Antwort

Star Strider
Star Strider am 24 Mär. 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 Kommentare
Hao Ming Low
Hao Ming Low am 24 Mär. 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 am 24 Mär. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by