how to determine coordinate from graph

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 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 Commenti
Hao Ming Low
Hao Ming Low il 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 il 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by