For questions about defining recursive functions, recursive algorithms and solving recursive equations.
0
votes
1answer
52 views
fit recursive function to data
I have a function $g(x, n)$, which is a recursive expression: $x$ is a variable and $n$ the number of iterations. In my case $n=3$ for all $x$. An example is the following:
...
1
vote
0answers
40 views
Integral of GeneratingFunction
I know that GeneratingFunction can be used to compute the generating function $\sum_{n=0}^\infty a_n x^n$ of a sequence $(a_n)_n$ via
GeneratingFunction[a[n],n,x]
...
6
votes
0answers
89 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 ...
3
votes
0answers
83 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 ...
6
votes
2answers
170 views
How can I define a sequence of functions?
I need to define a function fun, and then re-define this function iteratively. The code is given at the end.
First, a function ...
1
vote
1answer
116 views
How can I solve my recursion equation?
How can I solve the recursion equation given below?
I doubt there have no solution for the recursion equation because this is circulating recucrsion equation.
...
3
votes
1answer
86 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, ...
5
votes
1answer
104 views
Recurrences of lists
Assume we have a multi-dimensional recurrence, e.g.
$\qquad\begin{align*}
a_1 &= (1,2) \\
a_n &= (1,2) + a_{n-1} \quad, n>1
\end{align*}$
with the easy solution $a_n = (n,2n)$.
How ...
3
votes
2answers
70 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
...
0
votes
2answers
81 views
Problem with Looping/Recurrence - Null Results [closed]
I'm trying to create a function that maps over a list of bits, and either returns the original bit or "mis-reads" the bit itself. The idea here is to simulate transcription errors.
Here's the ...
2
votes
4answers
160 views
Recurrence relation in a table
I am trying to generate a list of x-values for a function using a module, where my x-value must increase by 'a' if the term ...
4
votes
0answers
72 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 ...
0
votes
0answers
27 views
Keeping memory to reduce the running time of recursion [duplicate]
I am using the following recursion in Mathematica to compute W[n, 1, s] for given n and s:
...
8
votes
5answers
214 views
Wrapping a function in count
I am working through the Programming Paradigms via Mathematica (A First Course) and am attempting to answer the following:
Use recursion to count how many times the argument can have its square
...
8
votes
4answers
288 views
Partitioning a list by recursion (Programming Paradigms via Mathematica (A First Course))
I am working through the course Programming Paradigms via Mathematica. One of the homework exercises for the section Recursion I: Passing the Buck is as follows:
Use recursion to partition a ...
1
vote
2answers
65 views
Using RecurrenceTable index to call elements of a vector
I am having trouble doing something that seems straightforward. I have a recursive sequence that I would like to produce which looks as follows:
...
1
vote
1answer
74 views
Recursive function taking functions as arguments
I'm trying to implement Lie brackets and derivatives of nth order.
For doing this, I've stumbled upon something I don't understand. Here is an illustration: First I define the functions:
...
2
votes
1answer
94 views
Recursion depth exceeded
Below is my code for numerical solving of PDE with Crank Nicolson scheme.
...
4
votes
3answers
114 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 ...
0
votes
3answers
128 views
List of Tribonacci Polynomials with Mathematica? [duplicate]
I want to list top ten of Tribonacci polynomials. I have following algorithm, but it doesnt work.
...
4
votes
1answer
100 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 ...
1
vote
1answer
144 views
Finding n-th term of a sequence of functions
Lets say, I have the following series of functions,
$f_1=a+1$
$f_2=a^2+2a+1$
$f_3=a^3+3a^2+3a+1$
Assume that $f_4, f_5,$ and $f_6$ are also known. However $f_n$ is not known as a function of $n$.
...
3
votes
3answers
289 views
Implementing the Farey sequence efficiently
There is of course the silly implementation:
FareySequence[n_] := Union[Flatten[Table[j/i, {i, 1, n}, {j, 0, i}]]]
However, there are numerous properties and ...
2
votes
0answers
51 views
RSolve and incomplete gamma function
I am interested in how Mathematica uses the incomplete gamma function to solve difference equations. For example, if we have this inhomogeneous, 2nd order equation and use ...
2
votes
2answers
79 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, ...
3
votes
0answers
155 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 ...
2
votes
0answers
98 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?
4
votes
0answers
125 views
Speeding up multilinear PRA branch-and-bound algorithm with worst-case exponential time scenario with respect to basic events
The algorithm is a branch-and-bound algorithm that calculates dominances for PRA, probalistic risk assessment. The task was to find faster ways to do it in numerical software such as Matlab but we ...
1
vote
1answer
93 views
Recursion evaluate Table power exceeded limit
I wrote 2 simple recursive functions for calculating the power of a table.
pol3[Tb_List, n_Integer?Positive] := If[n == 1, Tb, Tb.pol3[Tb, n - 1]]
and
...
5
votes
1answer
85 views
4
votes
2answers
140 views
Update a function avoiding infinite recursion
I am quite new to Mathematica and not completely familiar with functional programming. I am currently working with a function (call it foo) and wish to change its behaviour, for example, by adding 1 ...
22
votes
4answers
658 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 ...
2
votes
2answers
342 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]
...
1
vote
1answer
94 views
Unwanted hold in recursive function
I have a function (let it be called f) that does something useful for me and I want to be able to apply it to the elements of a list regardless of their depth and keep the list structure. For example ...
2
votes
1answer
77 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
...
3
votes
1answer
81 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
1answer
117 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:
...
14
votes
3answers
362 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 ...
2
votes
0answers
133 views
Am I entering this 2-variable recurrence correctly?
I'm trying to solve this recurrence with two variables.
...
2
votes
1answer
120 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 ...
0
votes
1answer
122 views
Creating Recursive Sequences
Quite a simple question, I reckon, however, even quite an extensive search hasn't helped me.
I want to define a recursively defined sequence that starts with defined ...
1
vote
0answers
138 views
RSolve doesn't solve this recurrence equation
RSolve[{1 == b ((c k[t - 1]^a - k[t])/(c k[t]^a - k[t + 1])) c a k[t]^(a - 1),
k[1] == b, k[3] == a}, k[t], t]
I tried to read the documentation in Help ...
5
votes
4answers
199 views
Can the general term my recurrence equations be written with Floor or Mod?
I want to know the formula for the general term of the following recurrence system. I guess it can be written with Floor or Mod. ...
2
votes
2answers
365 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) ]\\
...
4
votes
1answer
96 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
...
8
votes
4answers
195 views
Order items by closest to the previous
I have a list of 2D points (a table, imagine the data of a parametric plot shuffled)
I would like to join the points with a line that starts from one of them and always goes to the closest one.
I ...
3
votes
1answer
292 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.
...
3
votes
1answer
520 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
84 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 ...
1
vote
2answers
181 views
While-Loop Linear Projection
I'm would like to do a linear progression for a recursive relation of a consumption function. Combining my program skills and my sparse knowledge of mathematica, I was thinking about doing it in a ...