MATLAB: How do i get x value from Y input from matlab polynomial plot

graphinterp1plotpolynomialvaluex valuey input

Hi, I plotted a graph, and i would like to get the x value for a given y. here are the codes for it. To be specific, i would like to know the X value at 10%of the max value of Y. After runnign the code, i got for 10% of Y is 19.32231. so i want to know what is the corresponding x value from the graph
x = 0:0.1:7 y= -0.0025*x.^6 + 0.0483*x.^5 – 0.177*x.^4 + 0.0122*x.^3 – 6.2034*x.^2 + 2.6569*x + 192.94; y2= -0.0032*x.^6 + 0.0305*x.^5 + 0.1034*x.^4 – 0.469*x.^3 – 8.3568*x.^2 + 2.7083*x + 171.01;
plot(x,y); hold on plot(x,y2);
maxY=max(y); maxY2=max(y2);

Best Answer

I suggest using interp1:
maxY=max(y);
maxY2=max(y2);
y_10 = 0.1*maxY;
y2_10 = 0.1*maxY2;
xi = interp1(y,x,y_10)
x2i = interp1(y2,x,y2_10)
plot(x,y, xi,y_10,'+r');
hold on
plot(x,y2, x2i,y2_10,'+r');
hold off