Skip to main content

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 ...
István Zachar's user avatar
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 ...
Nasser's user avatar
  • 147k
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 ...
AsukaMinato's user avatar
  • 10.1k
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. ...
Fierce82's user avatar
  • 543
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 ...
jwhatthe's user avatar
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 ...
dingo_d's user avatar
  • 677
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_{...
amrods's user avatar
  • 637
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 ...
JungHwan Min's user avatar
  • 4,694
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 ...
Frederik Ziebell's user avatar
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. ...
work_in_progress's user avatar
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 ...
Vincent Tjeng's user avatar
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}] ...
tba's user avatar
  • 585
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 ...
Just Some Old Man's user avatar
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: ...
RecursionRecursion's user avatar
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 ...
A. Florio's user avatar

15 30 50 per page
1
2 3 4 5 6