Skip to main content

Questions tagged [recursion]

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

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
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
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
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
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
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)})$...
J. M.'s missing motivation's user avatar
27 votes
5 answers
2k views

Visualisation of a recursive function

Is there a way to nicely visualize recursive functions? (diagrams/plots) More specifically I'm looking for a way to make contrast (visually) between e.g. the cosine function which if continuously ...
Ellie's user avatar
  • 504
25 votes
1 answer
1k views

L-System in Mathematica

Here is some Maple code for drawing an L-System: ...
vito's user avatar
  • 8,988
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
20 votes
6 answers
2k views

How can I evaluate only a single step of a recursive function?

Let's say have a simple recursive function for the Fibonacci sequence f[0] := 1 f[1] := 1 f[n_] := f[n - 1] + f[n - 2] but I want to see how it will expand in a ...
Jakub Arnold's user avatar
19 votes
6 answers
5k views

Recursively appending elements to a list

In wanting to demonstrate the power of Mathematica, I wanted to show my 11-year-old son how we could validate that his sequences homework was correct. We could generate the next value in sequence in a ...
AnthonyMiller's user avatar
17 votes
4 answers
19k views

How to implement recursive function

I'm trying to do the following (taken from an answer by Watson to my question on Math SE): Start with $x_1=2$, say. Then define $$x_{n+1} = |\{i \in \{1,\dots,n-1\} \;:\; x_i=x_n\}|$$ i.e. number ...
Bobson Dugnutt's user avatar
16 votes
5 answers
1k views

How to create a spiral using Golden Triangles

Working with students in a pre-calculus class, an application of the sine law. They are working on a question that has them create a Golden Triangle (A golden triangle is an isosceles triangle in ...
Tom De Vries's user avatar
  • 3,780
16 votes
1 answer
2k views

Efficient backtracking with Mathematica

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("...
a06e's user avatar
  • 11.4k
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

15 30 50 per page
1
2 3 4 5
44