I have a set of points $\{x_i,y_i\}$ that represents a closed curve. I want to find a function $F(x,y)$ such that $F(x,y) = 0$ gives the needed curve and $F(x,y) \ne 0$ outside the curve.

For example, suppose I am given a set of points that forms a circle:

n = 16;
points = Drop[Table[{Cos[2 i Pi], Sin[2 i Pi]}, {i, 0, 1, 1/n}], -1] // N;

I use the Interpolation[..] Mathematica function:

args = Join[Table[{points[[i]], 0}, {i, Length[points]}], {{{0, 0}, -1}}];
F = Interpolation[args];

Here I have added a new point $(0,0)$ with value $-1$ in it to my set of points to give "a depth" to $F(x,y)$.

First question. Is that solution right? Can I be sure that my $F(x,y) \ne 0$ on non-curve points if I add "an inner" point with non-zero value to my set? What solution is more preferable?

Also I have a second (and main) question. Due the peculiarity of my problem I need an explicit expression for my curve in a given section. In other words I want to have an expression for my curve in terms $y = f(x)$ or $x = f(y)$ (does not matter) between near points. I need this $f$ and its derivative $f'$. Thereby $f$ should be an InterpolatingFunction object too (but one-dimensional).

Using Solve on F from previous example does not give a result.

How to get $F$ and $f$ (between given near points)?


In my example $F(x,y) = x^2+y^2-1$ and I can single out two explicit fucntions: $f_1(x) = \sqrt{1-x^2}$ where $x > 0$ and $f_2(x) = -\sqrt{1-x^2}$ where $x \leq 0$. Equations $y=f_1(x), y=f_2(x)$ and equation $F(x,y)=0$ represent the same curve (a circle). This is what I need: implicit function $F(x,y)$ and a set of explicit functions $f_i$.

Also I can single out another explicit functions:

$f_1(y) = \sqrt{1-y^2}$ where $y \leq x$ and $y \geq -x$; $f_2(x) = \sqrt{1-x^2}$ where $y > x$ and $y \geq -x$; $f_3(y) = -\sqrt{1-y^2}$ where $y > x$ and $ y < -x$; $f_4(x) = -\sqrt{1-x^2}$ where $y \leq x$ and $y < -x$.

Together they form a circle.

Update 2:

The given curve is closed and has no self-intersections. Locally $F(x,y)=0$ can be expressed as $y=f(x)$ or $x=f(y)$. This is what I need. I try Solve function but it does not give result for interpolating $F(x,y)$. Instead it gives an error: "Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system"

  • $\begingroup$ Might make sense instead to interpolate each coordinate separately as a function of a new parameter, call it t. So you would have x[t] and y[t] as parametrized functions. If you require x[y] or y[x] you could either (a) locally invert (say) x[t] to get t[x] and thus find y[t[x]], or (b) break the points into sections monotonic in one or the other variable, and use that to form interpolations of one in terms of the other. $\endgroup$ Mar 1, 2012 at 19:15
  • $\begingroup$ It does not give me the implicit function $F(x,y)$ (determinated within whole plane). Maybe I can construct it in some way based on $x(t)$ and $y(t)$ then I solve the problem. But now I wonder is there an evident/build-in method to obtain this $F(x,y)$ at once. $\endgroup$
    – ddd
    Mar 2, 2012 at 18:44
  • $\begingroup$ @ddd You can interpolate each coordinate separately and use implicization techniques to obtain F(x,y), such as computing the resultant: en.wikipedia.org/wiki/… $\endgroup$
    – shamisen
    May 13, 2023 at 17:53

2 Answers 2


Regarding your second question, f may be obtained in general via f=Interpolation[points]. Its derivative is given by f'[.3] (say) This, however, fails for your example because two points with the same x-coordinate appear (as it is a circle).

For instance, try f = Interpolation[Table[{i, Sin[i]}, {i, 0, 10, .1}]] and then Plot[f'[x], {x, 0, 2 Pi}].

Perhaps you could explain what it is you're actually trying to do.

EDIT: OK, you can do this for f1:

Quiet[f1 = FunctionInterpolation[Sqrt[1 - y^2], {y, -1, 1}]];

and for your F (that I randomly renamed to func)

func = FunctionInterpolation[-1 + 1*(x^2 + y^2), {x, -1.5, 
   1.5}, {y, -1.5, 1.5}]

Note that this is some function that vanishes on the unit circle. If all you want is that F(x,y) vanishes on (eg) the unit circle, there are infinitely many functions satisfying this; one of them is the one you gave.

  • $\begingroup$ Thak you for your remark. I added some explanation according to my example. $\endgroup$
    – ddd
    Feb 28, 2012 at 19:41
  • $\begingroup$ The problem is i do not know these Sqrt and x^2+y^2. I have a set of points that form a pretty complicated curve (without intersections). I need implicit function (any) that vanishes on this curve (determinated for all x,y and non-zero in non-curve points) and a set of explicit functions (they determinated only in some sections) such that their graphics coincide with curve $\endgroup$
    – ddd
    Feb 28, 2012 at 22:25
  • 1
    $\begingroup$ You seem to be asking too much, darksowa. For instance, if your points follow a lemniscate $F(x,y)$ = $(x^2 + y^2)^2 - (x^2 - y^2)=0$ then in a neighborhood of $(0,0)$ there does not exist any such $f$. $\endgroup$
    – whuber
    Mar 1, 2012 at 2:17
  • $\begingroup$ My curve has no self-intersections. Locally $F(x,y)=0$ can be expressed as $y=f(x)$ or $x=f(y)$. This is what I need. I tryed Solve function but it does not give result for interpolating $F(x,y)$. Instead it gives an error "Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system" $\endgroup$
    – ddd
    Mar 1, 2012 at 14:43
  • 1
    $\begingroup$ You will run into problems with cusps, too. Although the intended function may have none of these problems, the ones based on interpolating the points very well could have them. Furthermore, although it's fair to hope that you could assemble an atlas of local maps of the form $f_i(x)$ and $f_j(y)$, if they are created via interpolation from your discrete data, it is unlikely these functions will exactly agree on their areas of overlap! $\endgroup$
    – whuber
    Mar 1, 2012 at 17:07

In addition to that inner point, provide a bounding box (or other curve) with a constant value larger than 0. That way you will have an interpolating function that does what you want over a reasonable range.

You'll probably want to give more points on your curve. Here I double it to 32.

n = 32;
points = Drop[Table[{Cos[2. i Pi], Sin[2. i Pi]}, {i, 0, 1, 1/n}], -1];
innerpoint = {{0, 0}, -1};
bigsize = 10;
bigval = 5;
outerbox = Union[Join[
    Table[{{bigsize, j}, bigval}, {j, -bigsize, bigsize}],
    Table[{{-bigsize, j}, bigval}, {j, -bigsize, bigsize}],
    Table[{{j, bigsize}, bigval}, {j, -bigsize, bigsize}],
    Table[{{j, -bigsize}, bigval}, {j, -bigsize, bigsize}]]];
args = Join[Thread[{points, 0}], {innerpoint}, outerbox];

twodimFunction = Interpolation[args];

Interpolation::udeg: Interpolation on unstructured grids is currently
only supported for InterpolationOrder->1 or InterpolationOrder->All.
Order will be reduced to 1. >>`

 twodimFunction[x, y], {x, -bigsize, bigsize}, {y, -bigsize, bigsize},
  ContourLabels -> True, PlotPoints -> 80]

enter image description here

It's a bit fuzzy at some of the outer contours. No idea why; must just be a vagary of the plotting sampling. Setting the PlotPoints reasonably high helps to alleviate it visually, and shows that it is not the interpolation that is to blame.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.