how to determine coordinate from graph

4 vues (au cours des 30 derniers jours)
Hao Ming Low
Hao Ming Low le 24 Mar 2020
Commenté : Star Strider le 24 Mar 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?

Réponse acceptée

Star Strider
Star Strider le 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 commentaires
Hao Ming Low
Hao Ming Low le 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 le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by