-1

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.

james.sw.clark
  • 357
  • 1
  • 8
  • 20
  • So why can't you do the same for a parabolic curve as for a line? Your data forms a parabolic curve anyway so it's a good fit....? – kkuilla Dec 01 '14 at 10:32

2 Answers2

2

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)
freude
  • 3,632
  • 3
  • 32
  • 51
1

Assuming your two curves are just two vectors of data, I would suggest you use Fast and Robust Curve Intersections from the File Exchange. See also these two similar questions: how to find intersection points when lines are created from an array and Finding where plots may cross with octave / matlab.

Community
  • 1
  • 1
am304
  • 13,758
  • 2
  • 22
  • 40