Questions tagged [recursion]
For questions about defining recursive functions, recursive algorithms and solving recursive equations.
113
questions
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 ...
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 ...
33
votes
4
answers
2k
views
What tools can help in realizing tail recursion?
I had nice discussions with Leonid and Rojo that got me interested in tail recursion. Tail recursion is not always easy to realize with Mathematica, so it would be nice to have some tools to help with ...
13
votes
5
answers
7k
views
How to deal with recursion formula in Mathematica?
In engineering problems, I am always seeing many recursion formula.
For instance, In the book "The NURBS book", I discovered many recursion formula
Fibonacci $$f(...
3
votes
2
answers
274
views
Recursion doesn't happen any more or doesn't happen correctly if I store the recursive relationship in a variable first
I know the following code will form a recursion:
Clear["Global`*"]
u[i_, n_] := u[i - 1, n] + u[i, n - 1]
u[0, n_] := n
u[i_, 0] := i
u[2, 2]
(* => 8 *)
But ...
37
votes
3
answers
3k
views
How to clear parts of a memoized function?
I have a function of two variables, e.g.:
f[a_, b_] := f[a, b] = something f[a - 1, b - 1] etc
With the above code I used the concept of memoization to speed up ...
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 ...
4
votes
2
answers
1k
views
Recursion problem
I try to make designation
a = {Subscript[a,1], Subscript[a,2], Subscript[a,3]}
but receive mistake
$RecursionLimit::reclim: Recursion depth of 1024 exceeded.
...
47
votes
3
answers
4k
views
Smooth Peter de Jong attractor
Today I was playing with Peter de Jong attractor.
At the bottom of the page I've linked there are beautiful examples like:
My attempts are not so great:
It is around 10^5 points. For more than 5*10^...
6
votes
2
answers
1k
views
Plotting two recursive functions
I'm trying to plot two recursive functions (p and θ) on a map. So far I have:
...
21
votes
4
answers
2k
views
How to define a recursive pattern?
I want to translate this recursive syntactic definition into a Mathematica pattern1:
$$
\mathtt{x}:
\begin{cases}
\text{Null}\\
\{\textit{integer}, \mathtt{x}\}
\end{cases}
$$
In other ...
15
votes
1
answer
943
views
How can I define a Listable function only apply to a vector?
Consider the function f which should behave as
f[{{1, 2}, {3, 4}, {5, 6, 7}}]
...
9
votes
4
answers
5k
views
Implementing Picard's Iteration for solving ODEs
Picard's Iteration is a way of solving the IVP
$$y'(x)=f(x,y(x)), \quad y(x_0)=y_0 $$
It consists of defining the following sequence of functions recursively:
$$y_0(x):=y_0 \\
y_{n}(x):=y_0+\int_{...
9
votes
1
answer
1k
views
Compiling a recursive formula
My question is related to computing what is called "invariant measure" for a particular well known fractal - the Sierpinski triangle.
We have an array m of four two by two matrices, say
...
6
votes
2
answers
1k
views
Trying to build a function to compute divided difference for arbitrary list of points
As the title says Im trying to build a function to compute divided difference for arbitrary list of points.
The divided difference of a set of points $\{(x_1,y_1),\ldots, (x_n,y_n)\}$ where $x_j<...