Ma · Mathematics

How Do You Convert a Discrete Function Into a Continuous One?

Published By the 9to5Science editorial team

At a glance

  1. 1. Identify the data

    List the input-output pairs the continuous function must preserve.

  2. 2. Choose an interpolation

    Use straight segments for linear interpolation, or choose a smoother method if needed.

  3. 3. Define the function

    Specify the formula between data points and check that adjacent pieces agree at their endpoints.

  4. 4. Check the requirements

    Confirm continuity, and also check differentiability if the application requires it.

A discrete function gives values only at separate inputs, such as integers or a finite list of sample points. To make a continuous function that agrees with those values, you need to define what happens between the inputs. There is no single correct conversion: linear interpolation, splines, and other rules can all produce different continuous functions.

The usual practical answer is interpolation: keep the given values and fill in the gaps according to a chosen rule. Linear interpolation is the simplest method.

Linear interpolation between data points

Suppose you know two values, f(a)=uf(a)=u and f(b)=vf(b)=v, where a<ba<b. The straight line through (a,u)(a,u) and (b,v)(b,v) is

L(x)=u+v−ub−a(x−a),a≤x≤b.L(x)=u+\frac{v-u}{b-a}(x-a), \qquad a\le x\le b.

This formula gives L(a)=uL(a)=u and L(b)=vL(b)=v. For a sequence of data points (x0,y0),(x1,y1),…(x_0,y_0), (x_1,y_1),\ldots, use this formula separately on each interval [xi,xi+1][x_i,x_{i+1}]. The neighboring formulas agree at each shared endpoint xix_i, so the resulting piecewise function is continuous there. For finitely many ordered points, this gives a continuous function on [x0,xn][x_0,x_n]. With infinitely many points, continuity at any accumulation point also requires compatible limiting values.

Worked example: extending the values f(n)=n2f(n)=n^2

Suppose the function is known only at integer inputs, with f(n)=n2f(n)=n^2, and you want a continuous function on the real line that matches those values. For each integer nn, interpolate linearly from (n,n2)(n,n^2) to (n+1,(n+1)2)(n+1,(n+1)^2).

The slope on this interval is

(n+1)2−n2(n+1)−n=2n+1.\frac{(n+1)^2-n^2}{(n+1)-n}=2n+1.

Thus, for n≤x≤n+1n\le x\le n+1, define

g(x)=n2+(2n+1)(x−n).g(x)=n^2+(2n+1)(x-n).

For example, between 00 and 11, this gives g(x)=xg(x)=x. Between 11 and 22, it gives g(x)=1+3(x−1)=3x−2g(x)=1+3(x-1)=3x-2. At every integer nn, the interval formulas meet at g(n)=n2g(n)=n^2, so gg is continuous on R\mathbb{R} and agrees with the original values at all integers.

This extension is not the only possibility. The function x2x^2 is also continuous and matches n2n^2 at every integer. The two extensions differ between integers: at x=0.5x=0.5, the linear interpolation gives 0.50.5, while x2x^2 gives 0.250.25. The data alone do not determine which behavior between sample points is intended.

Choosing an interpolation method

Use the method that fits the purpose and the information you have:

MethodWhat it doesTypical use
Linear interpolationJoins consecutive points with straight lines; for finite ordered data, this gives a continuous interpolantSimple estimates between measurements
Polynomial interpolationFits a polynomial through the specified pointsSmall data sets or theoretical constructions
Spline interpolationJoins polynomial pieces smoothlySmooth curves through measured data
A model functionUses a chosen formula or physical modelWhen there is a reason to expect a particular shape

For finite ordered data, linear interpolation gives a continuous function when the pieces share their endpoint values. For infinitely many points, continuity at accumulation points additionally requires compatible limiting values. Linear interpolation generally does not guarantee differentiability at the joining points: the slopes on the two sides may differ. Splines can provide smoother joins, but they require additional choices, such as endpoint conditions.

A distinction about the word “continuous”

If a function’s domain is exactly the integers, continuity has a technical meaning different from extending it to the real line. With the usual topology inherited from R\mathbb{R}, every integer is isolated: a sufficiently small interval around it contains no other integer. Consequently, every function defined on Z\mathbb{Z} is continuous as a function from Z\mathbb{Z} to R\mathbb{R}, regardless of its values.

In most practical questions, “convert a discrete function into a continuous one” means: construct a function on an interval or on R\mathbb{R} that preserves the listed values. Interpolation addresses that goal.

For a finite collection of data points, a piecewise-linear extension is always possible. For an infinite set of inputs with accumulation points, matching values and continuity may not always be possible. If inputs approach a point cc, the values along every sequence of inputs approaching cc must converge to the same limit. If cc is one of the specified inputs, that limit must equal its specified value; if cc is not specified, the limit determines the value a continuous extension must take there. The data must be compatible with continuity at every such accumulation point.

Common mistakes

  • Assuming the data determine one curve. They determine values at the given inputs, not between them. State the interpolation or modeling assumption.
  • Confusing interpolation with approximation. Interpolation passes through the supplied points. A fitted curve may instead be chosen to track noisy data without passing through every point.
  • Assuming a continuous curve is automatically smooth. A piecewise-linear function is continuous, but it can have sharp corners where its slope changes.
  • Using a formula outside its intended intervals. A piecewise definition should specify which formula applies on each interval and should agree at shared endpoints.

To build a basic continuous extension, order the known points, connect each adjacent pair with a line segment, and define the resulting piecewise function. Choose a smoother interpolation or a model when the application calls for more than continuity.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.