Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
? find xi of given yi from a given table

Subject: ? find xi of given yi from a given table

From: Cheng Cosine

Date: 14 May, 2010 13:15:31

Message: 1 of 4

Hi:

 Suppose y is a function of x, and we have a set of data points from
experiment.

How do we determine the value of x_target corresponding to a target
value of y_target? If we know the function form of y = f(x), and then
we can use root-finding algorithms such as Newton method. But now we
only have discrete data points.

 Thanks,

Subject: ? find xi of given yi from a given table

From: Jan Simon

Date: 14 May, 2010 14:03:06

Message: 2 of 4

Dear Cheng!

> Suppose y is a function of x, and we have a set of data points from
> experiment.
>
> How do we determine the value of x_target corresponding to a target
> value of y_target? If we know the function form of y = f(x), and then
> we can use root-finding algorithms such as Newton method. But now we
> only have discrete data points.

Are you looking for INTERP1 ?

Jan

Subject: ? find xi of given yi from a given table

From: John D'Errico

Date: 14 May, 2010 14:28:06

Message: 3 of 4

Cheng Cosine <asecant@gmail.com> wrote in message <3e0c9d18-6f2c-4468-9e7a-a1ef12744b8c@37g2000yqm.googlegroups.com>...
> Hi:
>
> Suppose y is a function of x, and we have a set of data points from
> experiment.
>
> How do we determine the value of x_target corresponding to a target
> value of y_target? If we know the function form of y = f(x), and then
> we can use root-finding algorithms such as Newton method. But now we
> only have discrete data points.

IF the underlying functional relationship has a single value
of y for any value of x, then just swap x and y, then use
interp1.

If not, then you can use Doug Schwarz's intersections code
from the FEX to do this nicely. It will find the multiple
solutions.

If you wish to fit the data, doing some smoothing, then you
can use my SLM tools to do the fitting (also on the file
exchange.) slmeval can solve for the inverse that you wish
to find.

Note that sometimes, swapping x and y as I have suggested
will result in not that terribly good of an interpolant. For
example,

x = 0:.2:1;
fun = @(x) x.^2;
y = fun(x);

See that fitting this curve with a spline, in the direction y(x)
yields a very accurate fit. In fact, it will be exact, to within
floating point noise.

spl = spline(x,y);
xev = 0:0.0001:1;

std(ppval(spl,xev) - fun(xev))
ans =
      3.55121582665278e-17

But, suppose that we invert the relationship? How well does
a spline fit?

splinv = spline(y,x);
yev =0:0.0001:1;
funinv = @(y) sqrt(y);

std(ppval(splinv,yev) - funinv(yev))
ans =
        0.0125954702997721

It turns out that the inverse relationship is not well represented
by a spline near x == 0, since there is a derivative singularity
at that location.

HTH,
John

Subject: ? find xi of given yi from a given table

From: Cheng Cosine

Date: 15 May, 2010 03:37:11

Message: 4 of 4

Hi:

 What if the desired form of function has multiple input variables?

 Say, y = f(x1, x2).

 How do we determine the spline function?

 WHat if we have even more complicated case that both input and output
variables are multiple?

 E.g., [y1, y2] = g(x1, x2, x3)

 Are there available tools helping us?

  Thanks,

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us