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

learn more… | top users | synonyms

5
votes
1answer
113 views

Recursion and safety of SetAttributes[Function, SequenceHold]

Compare the timings below ...
5
votes
1answer
525 views

Solving recurrence relation using Mathematica defined in a piecewise way

I have a recurrence relation defined as following: RSolve[ { p[0] == p0, p[1] == λ p[0]/μ, p[i + 1] == λ p[i]/(2 μ) }, p[i], i ] Note that the relation ...
5
votes
1answer
256 views

Build recursion in parallel?

Problem Let's define a simple recursion. f[1] = 1; f[n_] := f[n] = f[n - 1]*n; If I evaluate f in parallel ...
5
votes
0answers
80 views

Second order differential equation with boundary conditions solving repeatedly

I want to solve a second order differential equation in the interval[-1:1], which does not have a analytic solution, \begin{eqnarray} y''(x) &=& k \phi^2(x)y(x) \\ \phi(x) &=& ...
4
votes
3answers
309 views

How to generate a recurrent sequence

How to generate this type of sequence? $$ f(n, x) = x f'(n-1, x) \hspace{2 mm}, f(0, x) = e^x$$ How do I evaluate it for numerical values for $x = 1$ or any number?
4
votes
3answers
175 views

Long waiting time for computing a summation

It takes a long time to compute the summation below, and I'd like to know if there are alternative ways to compute things faster. When replacing $15$ by $\infty$, then I should get $3^{1/3}$. I need ...
4
votes
3answers
189 views

Modify this code using Module and While

I have written a recursive function and would like to re-write the code using Module AND While to compare the timings. Here is my recursive function for f[n], where 6 n f[n] = f[n-1] + n! for n>0 and ...
4
votes
1answer
113 views

RSolve gives a Context::ssle error

I want to solve the following recurrence equation RSolve[{(k + 2) c[k + 2] q^(k + 1) - c[k] == 0}, c[k], k] During calculation in Mathematica I get this ...
4
votes
1answer
209 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: ...
4
votes
3answers
211 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?
4
votes
1answer
207 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) $$ ...
4
votes
1answer
216 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 - ...
4
votes
2answers
201 views

How to find a recurrence relation for a numerical sequence?

This question was inspired by Vladimir Reshetnikov's question (How to find a recurrence relation for a sequence?): Given a finite sequence of numbers, how can we find in MMA a recurrence relation ...
4
votes
1answer
142 views

RecurrenceTable with vector

Mathematica can do a RecurrenceTable with a vector, here is a simple example: RecurrenceTable[{x[n + 1] == 2* x[n], x[0] == {1, 2, 3}}, x, {n, 3}] with output ...
4
votes
1answer
517 views

How do I use RSolve to solve a system of recurrence relations?

I am trying to solve a system of recurrence relations as follows. ...
4
votes
2answers
140 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: ...
4
votes
1answer
318 views

Error Interpretation in NIntegrate

I am using a recursion algorithm developed by Migdal for Lattice Field Theory, and I have the following code: ...
4
votes
0answers
119 views

Efficient Generation of Subgraphs (or, unfriend a friend a day)

NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above. My friends ...
3
votes
2answers
137 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? ...
3
votes
2answers
204 views

Implementation of a recurrence relation for the polynomials appearing in the large order asymptotics of the Bessel functions

I would like to implement the recurrence relation for the polynomials $U_n(x)$ appearing in the large order asymptotics of the Bessel functions. The recurrence in question is ...
3
votes
3answers
183 views

Pare down list recursively

What is the best way to pare down a list whereby the $n$th number is removed from the list recursively? This ...
3
votes
4answers
151 views

Plotting recursive from a for loop

our assignment is that we have make a plot for the possition of 1's From the recursive function if a[n-1] is even then ...
3
votes
2answers
205 views

A problem about recursion formula of deCasteljau algorithm

I use mathematica to realize the deCasteljaul algorithm $$\vec{P}_{k,i}(u_0)=(1-u_0)\vec{P}_{k-1,i}(u_0)+u_0\vec{P}_{k-1,i+1}(u_0)$$ The graphics that deCasteljaul algorithm generated as below: ...
3
votes
4answers
459 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 ...
3
votes
1answer
161 views

How to make a simple tree yourself with defined distances for each generation?

I'm trying to make a function that generates a tree for spin spin analysis in spectroscopy. I though it would be pretty easy, but I'm totally stocked. The tree should look something like this: ...
3
votes
1answer
81 views

Mathematica taking too long to calculate recursive function

I have been trying to plot those specific recursively defined functions p1 and q1 in Mathematica: ...
3
votes
1answer
200 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 ...
3
votes
1answer
351 views

How to implement Condition programmatically?

I am writing my own symbolic functions with custom symbolic properties. So often I wish to introduce some automatic simplifications or evaluations, which return the same head as it's argument. This ...
3
votes
1answer
106 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. ...
3
votes
1answer
176 views

How can I get the general term of this recurrence equations?

Following is the recurrence relation: a[1] = 1; a[n_] := a[n - a[n - 1]] + 1 Array[a, 28] I tried to use RSolve, but it ...
3
votes
2answers
152 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: $ ...
3
votes
1answer
138 views

Using NestWhileList to determine smallest prime value in series

I have a function recursively defined as follows: $a_{n+1}-1=(a_n-1)\times lpf(a_n)$, whe $lpf(x)$ is the least prime factor of $x$. Now, given an initial value of $a_0$, I would like to find the ...
3
votes
2answers
253 views

Nonlinear recurrence relation

I entered the following recurrence relation into RSolve and it just gave the question back to me. $$a_{n+1} = \frac{(1+a_n +(a_{n−1})^3)} 3$$ Is there another way to get a formula for the nth term?
3
votes
1answer
212 views

Avoid crash in recursive Dynamic

With the following Dynamic cell, I can reproducibly crash Mathematica, so do not try this unless you have saved all your work! ...
3
votes
1answer
300 views

Transform recursion for coefficients into differential equation for generating function

Assume, one is given a linear recursion with polynomial coefficients for a sequence $(a_i)_i$, such as a[i] == i a[i-1] I would like to convert this recursion ...
3
votes
1answer
191 views

Converting this recursive function definition into nested sums?

Here's the recursive function I'm using: DH[n_, k_, s_] := Sum[Binomial[k, k - j] DH[n/m^j, k - j, m + 1], {m, s, n^(1/k)}, {j, 1, k}] DH[n_, 0, s_] := 1 Now, ...
3
votes
1answer
818 views

Solve pair of recurrence relations

[Corrected equations and added simple example] Can you solve a system of (loosely) coupled recurrence relations like this in Mathematica somehow? ...
3
votes
0answers
320 views

Solving recursion relations using Mathematica

I want to solve the recursion relation given in equation 2.7(a/b) on page $6$ of this paper. (..the initial seed is $F_1 = G_1 = 1$ and the functions $\alpha$ and $\beta$ are defined on page $5$ in ...
3
votes
0answers
94 views

An recurrence equation that can be solved in version 7 but not in version 8

A friend of mine showed me this code sample: RSolve[{a[n] == a[n - 5] + 1, Sequence @@ Table[a[i] == 1, {i, 5}]}, a[n], n] // Timing It's solved by version 7 in ...
2
votes
3answers
612 views

Recursive function on list

Please consider the following: I have to deliver the weekly customer demand data on time. I can start to produce my products one week in advance. So I was thinking ...
2
votes
2answers
101 views

Rising Recursion Relationships

Lets say I want to compute the following function in mathematica: $G[n,k]=G[n+1,k-1] + G[n+2,k-2]$ where I know that $G[n,0]=n$ and $G[n,1]=n^2$. So, for example, $G[3,2]=G[4,1]+G[5,0]=4^2+5$ or, ...
2
votes
1answer
2k views

Defining a recursive sequence

I want to define a recursive sequence and then ask Mathematica to print a specific value: Am I doing something wrong?
2
votes
2answers
647 views

defining recursively a function with multiple if conditions

I am trying to recursively define a function which satisfies the following system of equations and which depends on two parameters $n$ and $l$, $$ \begin{align} A(x, n, l) &= F[ A(x,n-1,l) ]\\ ...
2
votes
2answers
123 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 ...
2
votes
2answers
71 views

Optimize recurrence output

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

How to define functions for a parameter-dependent recursive sequence

I am trying to generate a two variable recursive sequence For instance on Mathematica, I did z[1] := {1, 1} B := {{t, 1}, {-1, t}} z[n_, t_] := B.z[n - 1, t] ...
2
votes
2answers
112 views

Understanding `NestList` with multiple functions

General question For a function f[n, a], where a is a list and n is a whole number, what is ...
2
votes
1answer
91 views

Implementing local variables of a recursive function with either Module or Block

First, some quick background: I have been eagerly learning Wolfram and Mathematica for two months now, and along the way have written about 250 pages of teaching material that has ballooned into a ...
2
votes
1answer
222 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 ...
2
votes
1answer
97 views

Notation not recursive enough?

My notation is not recursing enough. For example, Notation[W[a_ | b_] ⟹ foo[a_, b_]/foo[b_]] Notation[W[a__, b_ | c_] ⟹ W[a__ | c_]W[b_ | c_]] Then ...