Say for example I have data which forms the parabolic curve y=x^2, and I want to read off the x value for a given y value. How do I go about doing this in MATLAB?
If it were a straight line, I could just use the equation of the line of best fit to calculate easily, however I can't do this with a curved line. If I can't find a solution, I'll solve for roots
Thanks in advance.
If all data are arrays (not analytical expressions), I usually do that finding minimal absolute error
x=some_array;
[~,ind]=min(abs(x.^2-y0))
Here y0
is a given y value
If your data are represented by a function, you can use fsolve
:
function y = myfun(x)
y=x^2-y0
[x,fval] = fsolve(@myfun,x0,options)
For symbolic computations, one can use solve
syms x
solve(x^2 - y0)