0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – george2079
    Commented Jul 18, 2016 at 18:49
  • $\begingroup$ 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). $\endgroup$ Commented Jul 18, 2016 at 20:21

2 Answers 2

1
$\begingroup$
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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – george2079
    Commented Jul 20, 2016 at 21:50
1
$\begingroup$

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]

plot

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

$\endgroup$

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.