Questions tagged [recursion]
For questions about defining recursive functions, recursive algorithms and solving recursive equations.
659
questions
13
votes
7
answers
4k
views
Recursive function with if-statement
I am trying to represent the following function definition in Mathematica:
$$\begin{align*}
f(1)&=1 \\ f(2n)&= \begin{cases}f(n) & \text{if}\space n\equiv0\pmod{2} \\ 2f(n) & \text{if}...
6
votes
0
answers
550
views
Increasing recursion speed in Hull-White trinomial tree calculation
First timer here and have been finding these boards very useful in learning Mathematica.
I'm trying to implement a numerical procedure for the Hull-White trinomial tree in Mathematica. Despite using ...
8
votes
1
answer
16k
views
Defining a recursive sequence
I want to define a recursive sequence and then ask Mathematica to print a specific value:
Am I doing something wrong?
65
votes
2
answers
11k
views
How can I use Mathematica's graph functions to cheat at Boggle?
Boggle is a word game played with 16 dice and a 4x4 tray. This question is inspired by a Stack Overflow question about Boggle that I decided to solve using Mathematica. In addition to Mathematica, I ...
1
vote
2
answers
366
views
Recursion on a moving window
I need to apply some computations to a moving window of $N$ items in a time series and I am struggling with doing recursion and shifting the considered window.
To illustrate, please consider the ...
6
votes
1
answer
1k
views
Solving recurrence relation using Mathematica defined in a piecewise way
I have a recurrence relation defined as following:
RSolve[
{
p[0] == p0,
p[1] == λ p[0]/μ,
p[i + 1] == λ p[i]/(2 μ)
},
p[i], i
]
Note that the relation ...
11
votes
2
answers
3k
views
How can I solve a difference-differential equation?
How do I ask Mathematica to try to solve a recursive relation that defines a sequence of functions? For example, suppose I know that $g_n(x) = g_{n-1}'(x)$ for $n > 0$ and that $g_0(x) = e^{2x}$. ...
1
vote
1
answer
571
views
How to solve a problem in relative motion?
I have a project due tomorrow that I have been struggling with for a month. I am utterly stumped, any help would be appreciated. The problem is:
There is a ferris wheel, 30m in radius, set 80m ...
7
votes
1
answer
453
views
Setting $RecursionLimit across all parallel kernels
I'm trying to optimize an elliptic curve factoring method by running it in parallel. There is a recursive step which required me to set the recursion limit higher than 256, however when I try and run ...
6
votes
3
answers
2k
views
recursive integration
I am trying to do multiple integrations recursively. For instance, I would like to do the following equation for arbitrary integer $n$:
$\displaystyle R_n(t) = \int_0^t \mathrm dt' R_0(t-t') R_{n-1}(...
3
votes
1
answer
376
views
Avoid crash in recursive Dynamic
Bug introduced in 9.0 or earlier, persisting through 13.2 or later
With the following Dynamic cell, I can reproducibly crash Mathematica, so do not try this unless ...
1
vote
1
answer
177
views
Differentiation w/o assiging concrete values
v = Subscript[v, 0]*Sin[(Pi*S)/Subscript[S, 0]];
a = dv/ds v;
a = D[v, s]
returns
...
30
votes
7
answers
1k
views
Alternative ways to implement a triangular recursion
Triangular recursions are a class of algorithms that frequently turn up in computational mathematics. These recursions are expressible in the general form
$$T_k^{(n)}=f(T_{k-1}^{(n)},T_{k-1}^{(n+1)})$...
56
votes
5
answers
6k
views
How can I implement dynamic programming for a function with more than one argument?
Dynamic programming is a technique for avoiding the repeated computation of the same values in a recursive program. Each value computed is immediately stored. If the value is needed again, it is not ...