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

learn more… | top users | synonyms

6
votes
2answers
50 views

Recursive function with array of variables

I am trying to create a recursive function which works with an increasing array of variables. Since the formula is quite complex, i will try to simplify my example to the core of my problem. The ...
5
votes
1answer
175 views

How can I make a “self-referential” replacement operation self-contained?

Fairly often I find use for replacement rules that call themselves on the right-hand side of the rule, e.g.: ...
5
votes
1answer
61 views

Specifying Range of RSolve

When I input RSolve[{0 == q[n + 1]^2 + 3 q[n + 1] + 2 q[n + 1] q[n] - 6 q[n] + q[n]^2, q[0] == 1}, q[n], n] I get two complicated-looking complex solutions: ...
4
votes
2answers
80 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: ...
0
votes
0answers
35 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: ...
0
votes
1answer
146 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? ...
0
votes
2answers
102 views

Solving an Equation (Recursively)

I have the following Values: $a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=\frac{g_2}{20};a[5]=0$. I need to compute the value of $b[n]$ in the following equation $$a[n]=\sum _{m=0}^{n} (m-2) \;\;a[m] ...
5
votes
2answers
245 views
4
votes
3answers
163 views

How to solve an integral equation by iteration method? [duplicate]

How I can obtain $n^{th}$ approximation of the following equation $f(t)=t+\int_0^tds f(s)$ by iteration method?
5
votes
1answer
193 views

Setting $RecursionLimit crashes Mathematica 10

I have encountered what I shall presume is a bug: setting $RecursionLimit repeatably crashes the Mathematica 10 kernel: ...
3
votes
1answer
71 views

Find exact limit of recurrence relation $x_{n+1}=\cos(x_n)+1, x_0=1$

I did this: b[x_] := Cos[b[x - 1]] + 1; b[0] = 1; num = SequenceLimit[N[Table[b[n], {n, 1, 100}], 50]] I also did the listplot which shows a convergent value. ...
11
votes
2answers
176 views

ToExpression fails with long nested string expressions

Consider the following conversion from String to Mathematica Expression: ...
1
vote
2answers
43 views

Print argument of function that exceeds $RecursionLimit

Is there a way to print the argument of a function which results in a $RecursionLimit::reclim error? As an example, cosider the code ...
0
votes
0answers
63 views

Calculating the recursion at the Fourier domain

I would like to calculate the following recursion with mathematica $$f_n(x)=\int_{B}^{A}f_{n-1}(x-\omega)f(\omega)\mbox{d}\omega\quad\quad f_1(w):=f(w)$$ This is simply the convolution of $f$ with ...
23
votes
3answers
663 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 ...
0
votes
1answer
52 views

Transition matrix of order n [closed]

I am doing a work about Markov Chains and I have as task to determine, either by induction or by spectral methods, the form of the higher order transition matrix of the model. My transition matrix ...
1
vote
1answer
39 views

Replacing variables in an RSolve expression

I have a recursive expression, which is something like: $$ a(n,x)=f(x,y,m)\,a(n-1,x)+g(x,y)\,a(n-1,y) $$ where $f(x,y,m)$ and $g(x,y)$ are known. So the second $a$ depends on $y$ rather than $x$. I ...
3
votes
1answer
176 views

How do I built a zoomable Koch curve?

I'm new to Mathematica and my goal is to write a simple program in order to demonstrate self-similarity of the Koch curve by zooming in. Here is a good example of what I mean (it's a Java applet). I ...
0
votes
1answer
107 views

Can't plot recursive function

I am new to Mathematica and now I could use some help. Trying to plot any of these functions generates a $RecursionLimit exception and I am wondering why. ...
4
votes
1answer
128 views

Variable number of nested variable-range sums

I would like to express the following nested sum in Mathematica: $$ S(m,j,N) = \sum_{k_1=m+j-1}^{N-1} f(N,k_1) \sum_{k_2=m+j-2}^{k_1-1} f(k_1,k_2) \cdots \sum_{k_m=j}^{k_{m-1}-1} f(k_{m-1},k_m) $$ ...
0
votes
4answers
134 views

RSolve fails on a two-equation non-linear system

I have a system of just two recurrence equations, I need to solve them and so I use RSolve: ...
0
votes
0answers
54 views

How can I use a For loop in a recursive function?

I am creating a simple radix2 FFT algorithm (based on Cooley-Turkey) by using a recursive function to obtain the fft. The function is supposed to work on a list (assuming the length is a power of ...
1
vote
1answer
62 views

Limit as n -> ∞ for RSolve with Multivariate Recurrence Relation

I'm trying to solve the following when n -> ∞: ...
1
vote
0answers
19 views

Solving a pair of recurrence relations [duplicate]

Why does this RSolve[{y[t] == a*y[t - 1]}, {y[t]}, t] work, while this ...
0
votes
1answer
87 views

How to plot particular piecewise defined functions in mathematica

How to plot such functions in Mathematica? Let $a_0, p,g,c$ be any positive integers, defining: $$a_{n+1} = \begin{cases}\frac{a_n}{p} &, a_n \text{ divisible by p}\\ ga_n +c &, a_n \text{ ...
0
votes
0answers
135 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: ...
4
votes
1answer
164 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: ...
2
votes
0answers
121 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 ...
5
votes
3answers
226 views

Nested list to graph

The following nested list can be regarded as a representation of a (tree) graph: ...
0
votes
1answer
63 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: ...
1
vote
2answers
116 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 ...
2
votes
2answers
143 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 ...
3
votes
2answers
129 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? ...
6
votes
1answer
294 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 ...
0
votes
1answer
81 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 ...
1
vote
1answer
125 views

Defining a recursive integral sequence

I have a recursive integral sequence as follows: $$y_0(x)=1+r,$$ $$y_1(x)=-\frac{1}{\Gamma(a)}\int_0^x (x-t)^{a-1} y_0(t) dt,$$ $$\vdots$$ $$y_n(x)=-\frac{1}{\Gamma(a)}\int_0^x (x-t)^{a-1} y_{n-1}(t) ...
0
votes
1answer
100 views

How to solve the recursion equation that include the uncertain value i in it?

I write the following code of a recursion equation, but it can not work correctly. ...
2
votes
1answer
183 views

calculating a sequence of functions using iteration

I am trying to compute a sequence of functions using iteration and keep running into problems trying to use built in looping commands because of the recursive nature of the definition. The code below ...
11
votes
7answers
380 views

Concatenation of lists in a Fibonacci-like pattern

I am trying to create a List of elements that follow the general pattern: $$X_{n+1} = X_n X_{n-1}$$ where the operation on the right hand side is concatenation, i.e., joining. I want to achieve the ...
0
votes
1answer
106 views

Explicit, closed formula for recursive integral as a function of the recursive parameter

This is a follow-up of this question/answer. I'm working on a recursive integral more complicated than the one on the linked question, but this one can be used as an example. I would like to obtain ...
4
votes
1answer
199 views

Computing a series in terms of exponential function

Is there any way to compute the following series in terms of exponential function ? $$\sum_{k=0}^\infty Y_1(k)\;x^k$$ where $$Y_1(k) = \frac{(k - 1)!}{k!}Y_3(k - 1)$$ $$Y_2(k) = \frac{(k - ...
1
vote
1answer
226 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, ...
1
vote
1answer
374 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: ...
5
votes
1answer
125 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: ...
5
votes
3answers
403 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 ...
5
votes
1answer
190 views

How to deal with too much recursion

I have put together a very simple climate model based around four equations which define the state at time t based on time t-1, ...
3
votes
2answers
140 views

Rook walk and RecurrenceTable in Mathematica

This appears in a combinatorics book: $a(m,n)=2 a(m,n-1)+2 a(m-1,n)-3 a(m-1,n-1)$ It is a recurrence equation for the number of rook walks from $(0,0)$ to $(m,n)$. The initial conditions are: $ ...
2
votes
2answers
69 views

Optimize recurrence output

I have recurrence and I need to calculate first $N$ members of the sequence ...
9
votes
2answers
296 views

Recursive Integral for Volume of $n$-Ball

The volume of an $n$-ball (the $(n+1)$-dimensional analogue of a disk) of radius $r$ can be found by the following integral recurrence: $$V_0(r)=2r$$ ...
3
votes
4answers
320 views

Recursive function for calculating the arithmetic mean of a vector

I want to write recursive function for calculating the arithmetic mean of a vector. For $X(n)=\{1,2,3,\ldots, n\}$, the formula is ${\rm Mean}(X(n))=((n-1)\, {\rm Mean}((X(n-1))+X_n)/n$. My ...