Andre3600
Andre3600

Reputation: 17

how to calculate the value of a value with x in a graph and equation?

How could you calculate the value of y = [10 30 60], in the graph to obtain its value of x, some reference of how to apply a code?

 x = [63 50 38 26.5 19 13.2 9.5 4.75 2.36 1.18 0.6 0.3 0.15 0.01];
 y = [100 100 92 18 1 0 0 0 0 0 0 0 0 0];
 z=max (x);
 l=min (x);
 xq1 = -l:0.5:z;
 p = pchip(x,y,xq1);
 semilogx(x,y,'ob',xq1,p,'-r');
 hold on
 grid on;
 xlim([0.01 100])
 ylim([0 100])
 legend('Curva','Linea')

Example:

img

Upvotes: 0

Views: 252

Answers (1)

Spektre
Spektre

Reputation: 51845

so If I get it right you want x = f(y) for some x ordered descending polyline?

  1. find line segment that covers your y

    simply loop through all line segments and find all that complies one of these:

     y[i]<= y < y[i-1]
     y[i]>= y > y[i-1]
    
  2. interpolate the x position

    for simplest use linear interpolation:

     x = x[i] + (x[i-1]-x[i])*(y-y[i])/(y[i-1]-y[i])
    

    If you need use higher degree interpolations ...

so for example let y=10 then i=4 because:

1 < 10 < 18

so:

x = x[i] + (x[i-1]-x[i])*(y-y[i])/(y[i-1]-y[i])
x =  19  + ( 26.5 - 19 )*(10- 1 )/(  18  -  1 )
x =  19  +  7.5*9/17
x =  19  +  3.9705882352941176470588235294118
x =  22.970588235294117647058823529412

Upvotes: 1

Related Questions