# Sampling a continuous function to create sequence of discrete values

My question is straightforward: How do I convert a continuous function into a discrete-valued function?

The function I want to convert is the JacobiAmplitude function:

ϕ[t_] = With[{k = 1.01}, JacobiAmplitude[k t, k^-3]];

Plot[ϕ[t], {t, 0, 50}]


I am using RSolve to solve a second-order difference equation and want to add a discrete-time version of the JacobiAmplitude function to the model as a forcing term.

I'd like to put a discrete-time JacobiAmplitude function, ϕ[n], into the following difference equation:

RSolve[
{y[n + 2] - y[n + 1] + 0.99*y[n] == ϕ[n], {y[0] == 0, y[1] == 1, ϕ[0] == 0}},
y[n], n
];

ListPlot[
Transpose@Table[{y[n]} /. First[%],
{n, 0, 350}],
Joined -> True, PlotRange -> All
]


I'd immensely appreciate any assistance.

• i dont think you even need RSolve here, just do y[n_]:= y[n-1] - 0.99*y[n-2] +ϕ[n-2]. No need for phi to be discrete. Commented Jul 18, 2016 at 18:49
• If you need the discrete function because your evaluation is too slow, then you could try memoization. That is, y[n_] := y[n] = y[n - 1] - 0.99*y[n - 2] + ϕ[n - 2] (Similar to @george2079 's solution, but with an extra y[n] =; this will prevent redundant evaluations). Commented Jul 18, 2016 at 20:21

y[n_] := Evaluate[(y[n] /.
RSolve[{y[n + 2] - y[n + 1] + 0.99*y[n] == ϕ[n], {y[0] == 0,
y[1] == 1}}, y[n], n])[[1]]];


RSolve does not automatically Set the definition of y, so you need to assign it manually. Also, the condition ϕ[0] == 0 in your RSolve seems to be unnecessary.

• its good to see how this is done, but note in this case using the RSolve result is much slower than directly crunching out the sequence. Commented Jul 20, 2016 at 21:50

I think this is a simple approach to your problem.

ϕ[t_] := With[{k = 1.01}, JacobiAmplitude[k t, k^-3]]

y[0] = 0; y[1] = 1;
y[n_] := y[n] = y[n - 1] - 0.99*y[n - 2] + ϕ[n - 2]

DiscretePlot[y[n], {n, 0, 350}, Filling -> None, Joined -> True]


You might want to look this this documentation article for more information.