# Tagged Questions

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

286 views

### Integrating a periodic function

I have a periodic function ff: ff := Function[x, Piecewise[{{ff[x - 1], x >= 1}, {2 x, 0 <= x < 1}, {ff[x + 1], x < 0}}]] Plotting it works fine: ...
37 views

### Scoping in recursive function leading to unexpected results

I'm trying to implement Ramer-Douglas-Peucker line simplification in Mathematica, and I'm running into an issue with recursion. My implementation of the algorithm is below: ...
223 views

### Programming a recursive FFT with Mathematica

I'm trying to program a FFT using a recursive function in Mathematica, though my program is not getting me anywhere at the moment. Could you say what's wrong with it and what I can do to make it work? ...
125 views

433 views

### Caching RecursionLimit::reclim error

I am learning how to catch exceptions, RecursionLimit::reclim in particular. To see how it works, I came up with the following example: ...
291 views

### Creating a dynamic plot directly from the recurrence relation

I have the following recurrence relation that has no general solution: $$x(t+1) = \frac{x^2 + x(1-x)(1-sh)}{x^2 + 2x(1-x)(1-sh) + (1-x)^2(1-s)}$$ In Mathematica language it gives: ...
226 views

### Faster Ways to compute recursive summation

It takes a long time to compute the summation below, and I'd like to know if there are some better ways to compute things faster. I have used $3$ ways to calculate, but they are very unsatisfactory. I ...
389 views

### Nested list to graph

The following nested list can be regarded as a representation of a (tree) graph: ...
107 views

### How to define a function that operate with a base case recursively? [duplicate]

Let's start from the simplest case: say I have a function $f(x)=x$, and let's say I want to define a new function (of $x$) to be its $n$-th power $(f(x))^n$. How should I write the code? I tried: ...
258 views

### Summing Over a Variable Number of Indices

I am trying to figure out the best way to include a variable number of indexes of summation in a program. For example: Suppose I want to define a function $g[n,s]$ that returns the sum ...
194 views

### Solving a dynamic program via recursion

I'm trying to use recursion to solve a joint inventory/ dynamic pricing problem as in monahan, petruzzi and zhao 2004. I tried to solve for y[t] and ...
144 views

### Unset while running recursion

I am trying to run a recursive definition while at the same time clearing previously found values, so my memory is not completely consumed. I found this: How to clear parts of a memoized function? ...
305 views

### What is the most elegant way to specifiy a start case for recursion?

When writing recursive code that computes the least value at which a condition is true and various other scenarios it is often necessary to specify a base case. What I have done to supply this is ...
89 views

### Defining a formal Primitive Recursion

I'm searching for a way to define the function this wikipedia article call Primitive Recursion. It should have two functions as argument and it should return a function. I need this as helping in ...
182 views

1k views

### Why do I get an error message when for this type of recursion?

When I type the following code: mus[] = 0; mus[x__] := First[List[x]] + mus[Rest[List[x]]] What one would think would happen is that if, ...
575 views

### Solving a nonlinear system of recurrence equations

I am having two problems regarding Mathematica, and both of them are happening because it does not accept such inputs: ...
232 views

### How can I use a recursive function in a Module

I have a question about using a recursive function in a module. I made the following example to illustrate the question. The followwing code works: ...
440 views

### Solving recurrence sequence using an ODE

I'm trying to solve the recurrence a[n] == 0 for n < l a[l] == 1 a[n] == (l + 2(n - l) a[n - l] + (n - l)(n - 1) a[n - 1])/n(n - l + 1) for n >= l using ...