Skip to main content

Questions tagged [recursion]

For questions about defining recursive functions, recursive algorithms and solving recursive equations.

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 ...
J. M.'s missing motivation's user avatar
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 ...
Pillsy's user avatar
  • 18.6k
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 ...
Jacob Akkerboom's user avatar
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(...
xyz's user avatar
  • 635
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 ...
xzczd's user avatar
  • 67.1k
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 ...
user5878's user avatar
  • 371
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
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. ...
Igor Fomenko's user avatar
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^...
Kuba's user avatar
  • 137k
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: ...
Geo's user avatar
  • 461
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 ...
kjo's user avatar
  • 11.7k
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}}] ...
chyanog's user avatar
  • 15.6k
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_{...
user1337's user avatar
  • 1,088
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 ...
arkajad's user avatar
  • 581
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<...
Masacroso's user avatar
  • 1,117

15 30 50 per page
1
2 3 4 5
8