Questions tagged [recursion]
For questions about defining recursive functions, recursive algorithms and solving recursive equations.
601
questions
2
votes
1
answer
117
views
Pattern match with "+" sign
Can you pattern match with a "+" sign?
Here is the recursion...(which does not work)
...
1
vote
0
answers
84
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
32
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 ...
0
votes
0
answers
31
views
Using the recursion index to compare with a value in another list
I am trying to generate an arrivals and departures plot for a signalised junction with the following parameters:
lambda: rate of arrival
c: cycle length of traffic lights
g: length of time signal is ...
2
votes
3
answers
148
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.
0
votes
0
answers
48
views
Function for probability distribution approximation of a compound random variable
In the book (Klugman et al, 2019) on can see the
Example 9.12. The number of claims has a Poisson–ETNB distribution with
Poisson parameter 𝜆 = 2 and ETNB parameters 𝛽 = 3 and 𝑟 = 0.2. The
claim ...
3
votes
3
answers
99
views
How to test a recursive formula using Mathematica?
Through taking the derivative of $\binom{n}{k}$ w.r.t $n$ repeatedly, I found the recursive formula:
$$\frac{\partial^a}{\partial n^a}\binom{n}{k}=\sum_{j=0}^{a-1}\binom{a-1}{i}\frac{\partial^j}{\...
0
votes
1
answer
52
views
Recursive Functions in Mathematica
I have a dataset with 4 columns and want to take a column and apply some kind of function that subtracts the previous term. So I want to multiply the column by 2 and subtract all of the previous ...
2
votes
4
answers
202
views
what's the Mathematica command for a recursive formula?
I want to know the Mathematica command for
$$f(a)=\sum_{n=0}^{a-1} \frac{f(n)}{n!}, \quad f(0)=1$$
How to write $f(0)=1$ together with the summation? I used:
...
0
votes
2
answers
78
views
Memoization and recursions
My question is bolded within the text below.
Memoization speeds up a recursion that needs to recall a prior rule other than the last one calculated. For instance, on my machine, the following take 0....
0
votes
1
answer
85
views
Implementing While loop in module that will iterate correctly
I am attempting to write a module that prints an optimal path from a starting node to a destination node. The first node is 1 and the final node is 100 (though when module prints these they should be ...
1
vote
1
answer
101
views
Recursive relationship too slow
Writing:
...
2
votes
1
answer
76
views
How do we implement this two-valued recursive function using FunctionCompile?
I have the following recursive function that involves DivisorSigma:
...
0
votes
0
answers
40
views
TagSetDelay the Plus[ ] function for direcy use with Datasets
I am trying to define a particular behavior of the function Plus[] when the arguments are $n$ Dataset, with $n\geq 3$.
(The goal is to mimic the behavior of Plus[] with Datasets instead of numbers)
...
0
votes
0
answers
49
views
Algebraic substitutions in order
I have some symbols xp[m,n] that satisfy recursion relations, rule1, rule2, rule3. I would like to use the relations to reduce ...
6
votes
1
answer
103
views
Want to tally the arithmetic operations of a recursive computation
Say I have a recursive computation func[n], and it involves the standard arithmetic operations +, -, *, /. I want to know how many additions, subtractions, multiplications, and divisions where done in ...
0
votes
0
answers
93
views
Help with Error: Recursion depth of 1024 exceeded during evaluation
I am quite new to Mathematica. Please excuse my mistakes. I would appreciate if you could help me with the following set of commands.
...
2
votes
2
answers
105
views
Mathematica code for Newton's Method doesn't work [duplicate]
I am trying to program Newton's Method in Mathematica to compute the roots of $f(x)=x^3-6x^2+11x-6$ using the Do command but my code gives a ...
2
votes
2
answers
213
views
Defining a function recursively
I want to construct polynomials (or just function) $f_n$ from $f_{n-1}$ using mathematica. For some kind of reason, I didn't manage to do this. So basically something like a recurrence table, but for ...
0
votes
0
answers
44
views
Silly trouble expressing recursive formulas?
I am trying to code the following formulas:
I did it in the following way:
...
0
votes
0
answers
80
views
How to Solve this recurrence relation?
When I use RSolve[]
[![enter image description here][1]][1]
It would show this.
I want to solve it to a[n], the function of n & E
How to do that?
The original ...
2
votes
0
answers
87
views
Finding recurrence relation from an inexact numerical sequence
Consider the recurrence relationship
d[0] = 0;
d[i_] := (1 + Sqrt[1 + 4 d[i - 1]^2])/2 /; i >= 1
which generates the following sequence (generated by using <...
0
votes
0
answers
42
views
Introducing FindRoot in a ReccurrenceTable but problem with the starting point
I would like to introducing FindRoot in a RecurrenceTable, that uses the previous result as a starting point.
My equations are defined as following:
...
0
votes
1
answer
58
views
Basics for recursive functions [duplicate]
I am new to Mathematica and try to define a simple recursive formula which is illustrated as below:
...
0
votes
1
answer
65
views
2
votes
2
answers
101
views
How to implement If criteria for the NestList-Function
I have a function which bisects a list in two parts recursively. Unfortunately I have to select a number of iterations for the NesList-function which is just an ...
0
votes
1
answer
66
views
Trouble while trying to re-run open source code
I am a physics student and this is my first time working with Mathematica. I am trying to run the notebook mentioned here, titled "Amplification factors of the superradiant scattering of a ...
3
votes
1
answer
122
views
How to use Manipulate with ListLinePlot
I'd like to run Manipulate with 0<r<=4 that preserves the ListLinePlot of the recurrence table given with the colors shown. I'm looking to use the autorun feature in Manipulate to show how the ...
0
votes
3
answers
399
views
Python recursive bisection algorithm to Mathematica
I've been sitting on this problem for a while and i am kind of stuck. I am pretty new to Mathematica and have been trying to implement a recusive Algorithm, which splits/bisects a list of items in ...
1
vote
1
answer
47
views
How to calculate this function using a recurrence relation?
I have a function as follows
$$
R_{nl}(r)=r^l e^{-\frac{\mu r}{n}}\sum_{j=0}^{n-l-1}b_j r^j \tag{1}
$$
where
$$
b_{j+1}=\frac{2\mu}{n}\frac{j+l+1-n}{(j+1)(j+2l+2)}b_j \tag{2}
$$
and $b_0=2\mu^{3/2}$ ...
0
votes
1
answer
43
views
Substitution of sequences to derive recursive mean
I would have the following derivation to calculate the recursive moving average and I'd like to follow it as closely as possible in Mathematica.
For the sequence where $y(i)$ is considered as an ...
1
vote
0
answers
56
views
Avoiding infinite rule recursion
Assume I want to apply rule $R_1$ from a rule set $S$ to an expression $E$ just if it is "half safe", i.e., if the next application of $S$ to $R_1(E)$ does not yield $E$ again. (This ...
0
votes
0
answers
143
views
How can I speed up this pdf path integration calculation with a slow recursive function with 40^4 summed terms in each iteration?
I am writing a path integration code for a numerical approximation to a probability density function.
I essentially take some initial continuous probability density function p0 and then perform a ...
1
vote
3
answers
112
views
How to define this recursive function? [closed]
Consider the relation
$t_{k}(n) = 2 t_{k-1}(\frac{n}{2}) + f(n)$
Where $t_{0}(n) = n^p$ and $f(n)=\alpha n^q$.
How can I get an arbitrary element $t_{k}(n)$ for example with $p=2,q=1,\alpha=1$ using ...
0
votes
2
answers
103
views
How can I solve this recursion? [closed]
What is the best way to solve this recursion in Mathematica?
Thanks :)
1
vote
2
answers
85
views
What are the limitations of RecurrenceTable?
Background
Consider a recurrence relationship defined in terms of the following recursive functions (which works correctly):
...
1
vote
1
answer
37
views
Recursive Dirichlet convolutions and sum errors
I only have an informal knowledge of mathematical at best, learned entirely from modifying premade programs, and reading the documentation of functions, so I apologize if my question should be obvious ...
2
votes
1
answer
113
views
Wrong answer with RSolve function
The green function is defined as:
$\left\{\begin{array}{l}G_{0}=1 \\ G_{k}=\sum_{j=1}^{k} \phi^{\prime} G_{k-j},\quad k \geqslant 1\end{array}\right.$
where
$\phi_{j}^{\prime}=\left\{\begin{array}{l}\...
3
votes
0
answers
103
views
Sowing Once into Each of Many Lists – Any Better than Append?
In general
I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
1
vote
0
answers
120
views
How to solve a system with infinitely many equations?
I need to solve the following system of (infinitely many) equations. I am looking for $V(0,0)$
$t \in \{0,1,2.....\}$ with one caveat that $s \leq 1+t$ should hold.
$ s \in \{1,2,3,L-1\}$
fixed ...
0
votes
1
answer
84
views
How to implement this recursion relation?
I am trying to implement the following relation in Mathematica for any $k$:
$$\begin{align} t_{n,n_1, \ldots, n_k} &= \frac{1}{2} \sum_{m=0}^{n-2} \left( t_{m,n-m-2,n_1, \ldots, n_k} - \frac{1}{N} ...
0
votes
1
answer
59
views
Add list of vectors to list of vectors recursively
This question relates to Add a vector to a list of vectors whereas here I want to add list of vectors to list of vectors recursively.
Given:
...
2
votes
1
answer
48
views
NetChain with LinearLayer before a NetFoldOperator, how do I make the memory work?
I have problems using a recurring network built using the NetFoldOperator in cascade to a LinearLayer. What happens is that the ...
0
votes
1
answer
87
views
Finding the exact symbolic formula for a function defined recursively
Let me introduce the problem.
I have the following functions;
The first one is defined recursively
$h(i,j):=\frac{i-1}{j+1}h(i+2,j-2)$ and $h(i,0)=1$ where $i$ and $j$ are even integers, greater than $...
4
votes
1
answer
112
views
How to solve for multiple (cascading) recurrence relations
I am working with recurrence relations with a simple base:
\begin{equation}
Y_i = aY_{i-1} + (1-a)X_i \quad \mbox{and if $Y_0=0$ then} \quad Y_n = (1-a)\sum_{i=1}^n a^{i-1} X_i \tag{1}
\end{equation}
...
5
votes
1
answer
263
views
Recursion: Salamin and Brent equation for finding $\pi$
I am attempting to compute $\pi$ using the Salamin and Brent equation:
Salamin and Brent (1976): Set $a_0=1$, $b_0=\frac1{\sqrt{2}}$, $s_0=\frac12$. Then iterate:
$$\small a_k=\frac{a_{k-1}+b_{k-1}}{...
0
votes
1
answer
72
views
n-dimensional recursion [closed]
I am trying to set up a recursive function that generates n number of differential equations for Subscript[y, n][t]
This ...
2
votes
2
answers
84
views
Calculate the Viswanath's constant (Random Fibonacci sequences)
How Can I calculate first few digits of Viswanath's constant?
Viswanath’s constant ≈ 1.1319882487943 is a real number whose nth power approximates the absolute value of the nth term of some random ...
1
vote
1
answer
66
views
Generate Recursion Tree of Fibonacci Sequence
I'm using this example to study Mathematics.Example Demo. In this example, before generating recursion tree, she flats the function. But I have a difficultly to understand how flatten works, ...
1
vote
1
answer
68
views
Iterative and recursive approach to generate Fibonacci sequence
I'm new to use Mathematica and using this demo project to understand Mathematic demo example.
I modified example code to only plot the runtime of recursive version of Fibonacci sequence runtime:
...