Questions tagged [recursion]
For questions about defining recursive functions, recursive algorithms and solving recursive equations.
79
questions with no upvoted or accepted answers
11
votes
0
answers
944
views
Compile recursive function modifying global variables
How to compile recursive formula when it relies on more than a few global variables (global to the topmost compiled function)? It is unreasonable to pass on all such variables to each recursive ...
9
votes
0
answers
996
views
V 13.2 gives TerminatedEvaluation["RecursionLimit"] on code which works before. Why?
Update June 25, 2023. Problem still there in V 13.3. Added screen shot at end.
I was trying code which worked all the time:
How to extend a function by period and display it
I find that in V 13.2 it ...
9
votes
0
answers
214
views
Sum causes a recursion problem
Bug introduced in 8 or earlier and Fixed 13.3.1
Sum[((-1)^(i + 1)*Binomial[n, i]*(n - i)!)/n!, {i, 1, n}]
This cause a Recursion problem.
As the comment said, If ...
6
votes
0
answers
218
views
Improve recursive function (memoization)
These days I am trying to rewrite the following recursive function, in order to gain some speed. It is crucial because I end up using 4-5 similar functions, and I need to decrease execution time.
...
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 ...
5
votes
0
answers
356
views
Method of characteristics, recursion formulas
I'm helping a friend out with a problem. He needs to plot out the solution to a water surge in a pipeline.
I have all the parameters set and I've put the equations in Mathematica, but I can't get the ...
5
votes
0
answers
120
views
How to speed up solution of system of recurrence equations
I was wondering how I can improve the speed on this method for solving a particular system of coupled recurrence equations. The system is
$$
\begin{align*}
&V(m)=\alpha + \beta V(m+1)+\beta \sum_{...
4
votes
0
answers
53
views
Bug with LinearRecurrence and Slot/SlotSequence?
The code below runs without any error:
LinearRecurrence[{##}, {1}, 5]
Each term is the previous term squared, times the index of the previous term.
If the ...
4
votes
0
answers
49
views
Maximum number of recursions lower than $RecursionLimit
Consider the following code segment:
f[x_]:=Module[{y},
Print[counter++];
Return[f[x+1]];
];
$RecursionLimit=20;
counter=0;
f[0]
The function terminates ...
4
votes
0
answers
234
views
Generating Functions with multiple arguments
I want to solve the recurrence of Ackermann function using Generating Function in Mathematica.
...
4
votes
0
answers
155
views
Efficient Generation of Subgraphs (or, unfriend a friend a day)
NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above.
My friends ...
4
votes
0
answers
423
views
Am I entering this 2-variable recurrence correctly?
I'm trying to solve this recurrence with two variables.
RSolve[g[d, n] == 1 + g[d - 1, n] + g[d - 1, n - 1] &&
g[d, 0] == g[0, n] == 0, g[d, n], {d, n}]
...
3
votes
0
answers
108
views
Sowing Once into Each of Many Lists – Any Better than Append?
In general
I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
3
votes
0
answers
119
views
Iterative process causing segmentation faults
Often in Mathematica, I program in some iterative process (say, some random walk) in order to find maxima. I usually write some hacky code involving iteration, and using the construction:
...
3
votes
0
answers
576
views
Epsilon algorithm to accelerate sum's convergence in a functional approach
I am trying to learn to use Mathematica in an efficient way. Thus, I decided to spend some time on functional programming. I would like to implement the so-called epsilon algorithm, that is used to ...