Questions tagged [recursion]
For questions about defining recursive functions, recursive algorithms and solving recursive equations.
646
questions
0
votes
0
answers
75
views
How is my code going over the recursion limit?
I don't know how my code is exceeding the recursion limit of 1024.
...
0
votes
1
answer
75
views
Recursion not working for higher terms
I am trying to find the terms x9,x10,x11 and y6,y7,y8 and so on from the recursive relation given in the code.
...
0
votes
2
answers
175
views
Sorting a list of functions by exploiting the recursive structure
Given a list of functions list and a vector of arguments {t, a}:
...
0
votes
2
answers
134
views
Symbolic recursion
I have the two recursive relations:
...
0
votes
3
answers
105
views
Calculate Bernoulli numbers ( with a twist) [closed]
Mathematica has an inbuilt function BernoulliB that calculates $B_n$ for which,
$$\frac{t} {\left(e^t-1\right)}=\sum_{n=0}^{\infty} \frac{B_n}{n !}t^n $$
I need to ...
1
vote
0
answers
70
views
Understanding HoldFirst in QuickSort algorithm
I have read the implementation of QuickSort algorithm in WL from Roman Maeder's Computer Science with Mathematica (2000).
The implementation is shown below.
...
3
votes
1
answer
127
views
Recurrence formula evaluating with speacial counting of subscripts
Hoping to check some recurrance relationship like this
$a_1 = x$ and $a_2 = y$, with
$$
a_{2n+1} = a_{2n} a_{2n-1}
$$
and
$$
a_{2n+2} = a_{2n+1} + 4
$$
Tried
...
2
votes
2
answers
104
views
Optimization of a Markov сhain with symbolic transition rate
I am trying to work on 1D random walk that can move to left, right or stay with probabilities $p_i$,$q_i$,$r_i$ that changes with the site $i$. I am trying to simulate this by using a recurrence ...
1
vote
1
answer
156
views
How do you Solve a Simultaneous System of Recursions
Consider the following system of simultaneous recursions:
r[n] == s[n-1]
s[n-2] == r[n-3]
I am tring to solve this system (I have given a vastly simplified ...
1
vote
2
answers
70
views
Recursively applying a substitution
I have an expression like this:
2v[j-1]-(s[j]+1)(c[j]-c[j-1]) >= v[j]
I want to apply this recursively say k times. I can do one step like this:
...
5
votes
1
answer
120
views
Implementing recurrence relation for an integral
I would like to implement the following recurrence relation,
$$I_{n+1}=-\log(2)I_n-\sum_{k=1}^n(-1)^k\left(1-\frac{1}{2^k}\right)\frac{n!\zeta(k+1)}{(n-k)!}I_{n-k}$$
with initial conditions,
$$I_0=\...
3
votes
1
answer
227
views
How to write a recursive formula?
What is the Mathematica command for the recursive formula:
F[a_]:=Sum[(-1)^a Binomial[a,k] Log[2]^(a-k) F[k], {k,0,a}]
where
...
4
votes
1
answer
91
views
RSolve for system of equations and matrix power [closed]
I have a matrix
a = {{3, -2}, {2, -2}};
We can easily find the n-th power, $A^n$ using
MatrixPower[a,n]
We can also find the ...
4
votes
1
answer
95
views
How can I compute the $n$-th complete Bell polynomial?
I'm interested in computing the n-th complete Bell polynomial
$
B_n(x_1,..., x_n)
$ using the formula given as the last equation in the "Exponential Bell polynomials" section here (I tried ...
0
votes
0
answers
33
views
Solution to a vector recurrence equation
Suppose $n\ge1$ is fixed. Let $C_1,C_2,\ldots,C_n$ be given constants.
Consider the recurrence
$$
C_n[S_{1}^{(n)},S_{2}^{(n)},\ldots,S_{n-1}^{(n)}]=
\left[\binom{n}{1},\binom{n}{2},\ldots,\binom{n}{n-...
0
votes
2
answers
36
views
How to obtain terms defined by a recursion relation in terms of the first value without solving the recursion?
I have a set of coefficients $A_{i}^N$ where $i=0,\dots, N$ that obey a recursion relation that takes the form
$$A_i^N = C_i^N-\sum_{M=1}^N\sum_{k=0}^{N-M}A_k^{N-M}\psi_{i,k}^{N,M}$$
The coefficients $...
3
votes
1
answer
156
views
How is this type of piecewise function represented and calculated? [closed]
How is this type of piecewise function as follows in the picture represented and calculated?
Use:
...
1
vote
2
answers
113
views
Simulating the card game War with $m$ suits and $n$ values
I am trying to simulate the card game War to find approximations to the stopping time distribution for different types of decks, and study conditional probabilities of winning given a certain deck. (...
1
vote
2
answers
73
views
Iterate symbolic expression
I'd like to symbolically iterate this formula $1,2,...,n$ times: $$f(z,u)=\frac{z}{1-z}f(z,1)+\frac{zu}{1-zu}f(z,zu)+\frac{z^2u}{1-z^2u}f(z,z^2u).$$
I tried using ...
2
votes
0
answers
63
views
Unexpected `LinearRecurrence` behavior in 13.2
From the definitions, I expect LinearRecurrence[{1}, {k}, 10] to be a constant array.
...
7
votes
1
answer
265
views
Recurrences related to Ramanujan's 1/pi formulas for level 10?
In the course of my research years ago, I came across three integer sequences related to Ramanujan's pi formulas but for level $10$. Their recurrence relations may be important. (Just like the level $...
1
vote
2
answers
86
views
SummaryBox and Recursion
How can I make it so that what is under the dropdown block is not calculated/constructed at once? Example code:
...
3
votes
2
answers
153
views
Recursive function with subscript
I am trying to define a recursive function with a subscript. Something similar would be $f_{n+1}(x) = \int 3 x f_{n}(x)dx$. I've tried lists, For function, ...
1
vote
1
answer
88
views
A recursion in a sum [closed]
I wish to use a recursion to continue the updating n2, n3, etc., up to n30. Probably simple concept for an experienced MM user. Sorry.
...
3
votes
1
answer
74
views
Use two derivative rules and iterate several times to get the simplest expression of higher derivative
I have 2 rules of recursive relation of the derivative, I want to use it several times get the higher derivative on [\Theta] of ...
0
votes
2
answers
61
views
Recurrent equation with UnitStep function using RSolve
I have the following equation to solve
$$a[n+1] = a[n] + 6 - 100\cdot \theta(a[n]-100)$$
where $\theta(x)$ is the Heaviside step function. So I tried the following
...
0
votes
1
answer
131
views
Kernel crashes after long iterations
I am trying to get a numerical root of a function defined as below. But after some large recursion the kernel get crashed. But for relatively low recursion(10000) that does not make any problem. But I ...
1
vote
2
answers
98
views
Module returning Null even with Module as a Return parameter
I'm currently trying to implement Newton's method of approximating roots to approximate the root of 2. I looked into some possible reasons as to why it would return Null, such as the scope of the ...
9
votes
0
answers
605
views
V 13.2 gives TerminatedEvaluation["RecursionLimit"] on code which works before. Why?
Update June 25, 2023. Problem still there in V 13.3. Added screen shot at end.
I was trying code which worked all the time:
How to extend a function by period and display it
I find that in V 13.2 it ...
0
votes
1
answer
78
views
Problem with For Loop when evaluating a recursive function at multiple points
I am running into problems with my For loop when trying to evaluate my expression. Fix some parameter values :
...
7
votes
4
answers
439
views
Plastic number rectangle
I'd like to find a nice recursive way of making this image
based on the plastic constant
Here's a start
...
3
votes
1
answer
221
views
Recursive function Catalan triangle
I'm trying to learn how to build a recursive function. However, I'm not sure to understand how to set a "limit".
Here is what I'm trying to make.
I want a function that gives me the i,j ...
1
vote
2
answers
137
views
Speed up calculation of recursively defined list
I have two lists $a$ and $b$ of length $n$ and $n-1$ respectively (typically I have $n \approx 1000$).
I have to compute a list $\theta$ of length $n$ which is defined recursively by the following ...
0
votes
0
answers
101
views
Recursive Sum not evaluating correctly
I'm trying to evaluate the following sums that nest into eachother:
$$
m_k=\frac{k}{k-1} \left(e^{\gamma}+ \sum_{i=1}^{k-2} {k-1\choose i} \frac{m_i}{i} \right)
\\
m_1=e^\gamma
$$
and
$$
\kappa_n = ...
1
vote
2
answers
132
views
Recursion with Sum
Using RSolve I tried without success to convert the recursive relation to a non-recursive function. How can I do this?
...
1
vote
1
answer
103
views
Plot of a recursive expression having a parameter
I have a recursive expression defined as
$$
h_u= (1-a)(1-b) h_{u-1} + \sum_{k=2}^{u-1} (1-a) b h_{u-1-k} - \sum_{k=2}^{u} h_{u-k} - \sum_{k=1}^{u+1} \Lambda_{u,k}
$$
where $\Lambda_{u,k} = \sum_{m=u-k+...
2
votes
1
answer
95
views
Evaluate a double sum using Mathematica
I am evaluating using Mathematica, the double sum $\sum_{u=0}^\infty \lbrace \sum_{k= u+1}^{u+y}[\dfrac{(1-a)}{4} (3/4)^k + 3a[(\dfrac{1}{2})^{k-1} - (\dfrac{3}{4})^{k-1} ]\rbrace $, where $'a' $ is a ...
3
votes
4
answers
317
views
Factorial implementation using FixedPoint
I implemented the factorial function:
fact[0] = 1
fact[x_Integer?Positive ] := x*fact[x - 1];
f[4] yields 24 as expected
I tried a different version of the ...
0
votes
0
answers
63
views
Compile error in recursive code due to large integer
I am trying to implement a compiled version for the original algorithm that is supposed to run faster . It works fine for small iteration loop number when max=100. However, when loop number gets ...
2
votes
1
answer
103
views
Implement recursion one step at a time with a function of more than one variable
i am trying to implement a recursive difference equation step by step, by implementing rules, similar to Rojo's method in this thread: How can I evaluate only a single step of a recursive function?
...
3
votes
2
answers
278
views
Recursive function in Mathematica
I need to implement the following recursive function in Mathematica.
$$F[-2*a,b,2b;2]=\left(\frac{a-1/2}{a-1/2+b}\right)F\left[-2*(a-1),b,2b;2\right]$$
The conditions of the functions are:
if $a=0$, ...
4
votes
3
answers
276
views
How to create a sequence of functions defined recursively?
I'm trying to create a Table of functions where each new element is defined recursively via indefinite integration of the previous one. I've tried doing:
...
2
votes
2
answers
321
views
Why does System`Private`ConstructNoEntry[Quantity, 1, "kg"] enter a Recursion?
System`Private`ConstructNoEntry[BesselJ, 0, x]
works fine, and outputs
BesselJ[0, x]
However,
...
1
vote
0
answers
81
views
Solving a 2D recurrence diagonal-by-diagonal
I have a 3D recurrence relation -- which I know can be hard for Mathematica to work with, so I boiled it down to 2D.
We have two functions, $f_1(i,j)$, $f_2(i,j)$ defined on the state space $\{(i,j) | ...
0
votes
0
answers
77
views
How to do this recursion relation in Mathematica effectively?
I have a function $h_{\Delta,l}(r,\eta)$ satisfying
\begin{equation}
h_{\Delta,l}(r,\eta)=\tilde{h}_{l}(r,\eta)+\sum_{k}\frac{c(k)}{\Delta-(1-l-k)}r^{k}h_{1-l+k,l+k}(r,\eta)
\end{equation}
where $k$ ...
1
vote
1
answer
110
views
RSolve with integer and boolean variable
I have a recurrence relation with two variables $i, b$ where
$i \in \{0, \ldots, n-1\}$ for some parameter $n \in \mathbb{N}$; and $b\in \{0,1\}$.
I tried to solve it using RSolve, but the function ...
2
votes
1
answer
129
views
Pattern match with "+" sign
Can you pattern match with a "+" sign?
Here is the recursion...(which does not work)
...
1
vote
0
answers
100
views
Why Mathematica don't set \$RecursionLimit and \$IterationLimit very big by default? [closed]
For my current program in Mathematica, sometimes I will encounter an error regarding \$IterationLimit and \$RecursionLimit. So I always set these two numbers to very large at the starting of every ...
0
votes
1
answer
38
views
Recursive error encountered when updating rules of assignment [closed]
I'm working on a problem which requires associating a single (complex) number with a pair of binary vectors. I'm doing this by creating a set of assignments through a function I call ...
2
votes
3
answers
161
views
Solving equation with delay term
I am trying to solve an equation looks like this...
x[t] == t^2 + x[t-10]
How can I obtain a numerical solution for x[t] in Mathematica?
Thanks.