Questions tagged [recursion]

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

Filter by
Sorted by
Tagged with
5 votes
2 answers
117 views

Building up a sequence dealing with a complex recursive scheme

Suppose I have multiple lists, the first one contains 2 elements, the next one 4 elements, the next one 8 elements, and so forth. Let these elements be labeled as Gij where i refers to the list it ...
Ibrahim's user avatar
  • 169
2 votes
1 answer
155 views

Recurrence relation for multivariate polynomials

I am trying to define a function which recursively computes a polynomial associated to every binary string: ComputePoly[s_]:=(** Recurse on the string s**) For ...
pre-kidney's user avatar
2 votes
2 answers
479 views

Why does Mathematica not evaluate the difference recurrence using `RSolve` or `RecurrenceTable`?

Mathematica does not evaluate the following recurrence of two variables using RSolve and only echoes the input: ...
hengxin's user avatar
  • 840
9 votes
1 answer
599 views

What do RecursionLimit and IterationLimit actually set?

The following recursive functions respectively calculate the length of a Short-cut Collatz Conjecture series and perform a pointless demonstration recursion: ...
Jerry Guern's user avatar
  • 4,602
8 votes
4 answers
681 views

Extract all Values from nested Association

Considering we have an Association: ...
Michiel van Mens's user avatar
21 votes
4 answers
2k views

How to define a recursive pattern?

I want to translate this recursive syntactic definition into a Mathematica pattern1: $$ \mathtt{x}: \begin{cases} \text{Null}\\ \{\textit{integer}, \mathtt{x}\} \end{cases} $$ In other ...
kjo's user avatar
  • 11.7k
6 votes
1 answer
196 views

Closed form of two-layer recurrence

I am trying to find a closed-form expression for $A(0)$, described by the following recurrence forms, as a function of $L$ and $d$: \begin{align} A(\ell) &= 1 + 2^d A(\ell+1) + \sum_{g=0}^{d-1} \...
Sweeters's user avatar
  • 161
3 votes
1 answer
304 views

Kernel crashed after $RecursionLimit = Infinity

$RecursionLimit = Infinity; T[n_, k_]:= T[n, k] = If[n == 0 || k == 1, 1, T[n, k-1] + If[n<k, 0, T[n-k, k]]]; Table[T[n!, n], {n, 1, 9}] Without ...
Vaclav Kotesovec's user avatar
2 votes
2 answers
157 views

How to build recursive function which only remembers every pth value and the last two values?

I need to create a recursive function of the natural numbers $f$ which only remembers the last two values it has found and every $p$th value. Below is the form of the code that I am working with, but ...
math_et_physics's user avatar
14 votes
3 answers
697 views

Mimic a procedural, recursive clustering algorithm for site percolation using functional programming

Sorry in advance for my logorrhea: I just want to make sure all of the information is here. Context and Question I am investigating site percolation on a square lattice. I have a working, depth-...
march's user avatar
  • 23.4k
3 votes
2 answers
2k views

Import nested JSON file [duplicate]

For a project where I receive JSON messages from a web server I was trying to convert these messages into a format that can be used easily within Mathematica. Because JSON also consists of key-value ...
Aart Goossens's user avatar
5 votes
2 answers
2k views

Recursive Euclidean algorithm in Mathematica

Can anyone explain to me how do I use a recursion, if I don't know the limit? For example, I need the remainder $r$ of the Euclidean algorithm for $\gcd(a,b)$ which equals $0$. I figured out that the ...
zermelovac's user avatar
0 votes
2 answers
144 views

Using Nest on a function that takes a function as one of its arguments [closed]

I have a function, nS[f_, xk_], which takes as arguments a function f and a vector xk. It ...
R. Bowman's user avatar
2 votes
0 answers
348 views

Using Mathematica to solve a recursive system of differential equations [closed]

I believe I have a difficult problem to work on specially because I don't have any previously experience using Mathematica in this kind of situation. So I'll try to describe it as best as I can hoping ...
André Oliveira's user avatar
2 votes
1 answer
404 views

Computing a recurrence table backward

I am trying to understand how to compute a recursive equation backward say n = 10 to n = 1. I am trying to solve a PDE for which ...
Kausik's user avatar
  • 197
2 votes
1 answer
476 views

Usage of Piecewise/RSolve to solve an equation based on condition

I am trying to compute price of call option on a stock using the finite difference method. I have a VBA code for it, and I am trying to find out how I can use Mathematica memoization functions and ...
Kausik's user avatar
  • 197
2 votes
0 answers
176 views

Recursive computation using Piecewise [closed]

I am trying to create an array using a series of equations using Piecewise. I am stuck in one of them. I am just putting a simplified version of code as below. I ...
Kausik's user avatar
  • 197
2 votes
2 answers
615 views

Find recurrence relation for a sum

Let's say I want to find a recursive equation for an exponentially weighted moving average EV[t_]:=(a-1)/(a^t-1)*Sum[a^(t-i)*x[i],{i,1,t}] I can do that manually ...
cryo111's user avatar
  • 283
1 vote
1 answer
308 views

RSolve with integrations

I want to solve this question with Mathematica. $$T_0(t)=c(t),\quad T_n(t)=a\int_0^t T_{n-1}(s)\, \mathrm{d}s+b(t).$$ Is it possible to solve $T_n(t)$ with RSolve?...
eccstartup's user avatar
5 votes
0 answers
120 views

How to speed up solution of system of recurrence equations

I was wondering how I can improve the speed on this method for solving a particular system of coupled recurrence equations. The system is $$ \begin{align*} &V(m)=\alpha + \beta V(m+1)+\beta \sum_{...
amrods's user avatar
  • 637
1 vote
2 answers
733 views

Express recursion formula by Nest function

I'm fairly new to Mathematica and I have to express a formula by Mathematicas Nest-function. I'd like to find the solution for my formula by my own, thats why I ...
Marschal's user avatar
1 vote
1 answer
128 views

Calculating a function repetitively without using a For loop

In my programme I have defined all these functions: ...
johnhenry's user avatar
  • 193
3 votes
1 answer
222 views

Can Mathematica solve this type of recurrence?

I have the following recursively defined equation: ...
Eleven-Eleven's user avatar
0 votes
2 answers
111 views

Writing a function with variable arguments [duplicate]

I want to write a function which takes multiple arguments varying from 1 to n, where each argument is a triplet. sublistProduct[{$a_1,b_1,c_1$},{$a_2,b_2,c_2$},...] = { $\Pi_{i=1}^{i=n}a_i ,\Pi_{i=1}...
drdebmath's user avatar
3 votes
2 answers
884 views

How to create a recursive TreeGraph

How could I create a recursive tree graph, such as one defined by the following: A family of trees $T_n$ are defined recursively as follows, for all integers $n \ge 1$. The tree $T_1$ consists of a ...
Brett Jackson's user avatar
2 votes
1 answer
172 views

How to solve for the closed form of this recurrence?

For integers $L,k \geq 0$: $$T(L,k) = \begin{cases} 0 & \text{if }k \geq d, \text{ever}\\ -a_{k} & \text{if }L=0 \text{ and } k<d\\ a_dT(L-1,k+1) - a_{k}T(L-1,0)& \text{if } L>0 \...
AJJ's user avatar
  • 155
6 votes
1 answer
782 views

Compile, "global variables" and recursion

I am trying to do something similar to this, namely to make a Compile'd function outer that itself calls a ...
Marius Ladegård Meyer's user avatar
1 vote
0 answers
115 views

Index change in a recursive definition

Assume I have the following recursive definition: ...
Anna's user avatar
  • 11
2 votes
1 answer
87 views

Evaluate recursive funtion as a whole before computing a recursive step

I'll try to make a basic example of my problem with $n$ being an array of elements, ex. $\{1,2,2,3,3,3\}$: If i have a sum which needs a computed value i would like to compute it beforehand and store ...
kon's user avatar
  • 263
4 votes
2 answers
1k views

Recursion problem

I try to make designation a = {Subscript[a,1], Subscript[a,2], Subscript[a,3]} but receive mistake $RecursionLimit::reclim: Recursion depth of 1024 exceeded. ...
Igor Fomenko's user avatar
1 vote
1 answer
441 views

Iteration convergence of Newton approximations

I am trying to determine for which initial values Newton's approximation of specific functions (EX: f(x)=x^2 -1)converge and to what numbers it will converge to. *Where Newton's approximations are x[...
meariMD's user avatar
  • 193
2 votes
1 answer
256 views

Getting the first $n$ terms of a recursion relation

Given a recursion relation, I would like to generate the first $n$ terms (automatically) without having to go term by term. Background Each term is of the form $a_{n}(t)$, that is, $a_{n}$ is a ...
Jack's user avatar
  • 121
3 votes
1 answer
259 views

How do I make Mathematica nest argument changes?

I want something like Nest[f,x,n], but what where f is an argument change like a pushforward and x[t] is a function, for example, symbolically, and not in any sort of code: $$ F{x[t]} \equiv x[2t + 1]...
mhm's user avatar
  • 33
7 votes
2 answers
1k views

Finding large Collatz Sequences, trying to improve speed

Background: I am already very much in love with Mathematica but I am also a novice. So far I have only gathered experience in procedural programming in Python. Generally speaking I am trying to ...
Spaced's user avatar
  • 195
3 votes
3 answers
697 views

Delay difference equation

How can I correctly specify and solve a system of delay difference equations in mathematica similar to NDSolve with regard to delay differential equations? For example if I want to "see" the values ...
holistic's user avatar
  • 2,985
3 votes
1 answer
368 views

RSolve and a recurrence relation

In the book An Introduction to the Analysis of Algorithms there is a recurrence relation for the number of compares used in Quicksort algorithm: $$ C_N=N+1+\sum_{0≤k≤N-1}\frac{1}{N}(C_k+C_{N−k−1}) $$ (...
user4510038's user avatar
4 votes
1 answer
207 views

How can I implement this recurrence equation in Mathematica?

I asked a similar question yesterday but today I realized that I was implementing the wrong function. I have tried changing the implementation but I can't get it to work. Problem: There is a river ...
Lightvvind's user avatar
0 votes
1 answer
80 views

Recurrence doesn't work together with maximize

When I'm trying to use a recurrence relation involving maximize it simply fails to compute anything... ...
ResearchEnthusiast's user avatar
2 votes
2 answers
447 views

How can I express this recurrence function in Mathematica?

\begin{equation} r_{i+1}=r_{i}+V_{i}{\Delta}t \end{equation} Where \begin{equation} V_{i}=(0.01, 0.40) \end{equation} and ${\Delta}t$ is the difference in time. My implementation (this is for ${\...
Lightvvind's user avatar
2 votes
1 answer
326 views

RecurrenceTable [closed]

I got an error saying ...
Bohan  Lu's user avatar
  • 139
0 votes
2 answers
417 views

Help Solving A Recusive System: "$RecursionLimit::reclim: Recursion depth of 256 exceeded."

Was wondering if anyone had any tricks/ideas on solving this system of recursive equations I have. Essentially my goal is to have J2 equal to zero, but to understand how tweaking several parameters ...
user1886681's user avatar
-1 votes
1 answer
14k views

Recursion depth of 1024 exceeded [closed]

I'm not sure why this code is giving the error :( f[0] = 0; f[n_] := f[n] = DigitCount[n, 10, 1] + f[n - 1]; f[1016]
Raksha's user avatar
  • 633
3 votes
2 answers
374 views

Function to Represent Recursive Integral

I'd like to represent the following recursive integral equation to evaluate/graph (for $n\leq3$): $$K_{i,n}\left(x\right)=\int_{x}^{\infty}K_{i,n-1}\left(y\right)dy$$ where $$K_{i,0}\left(x\right)=...
Joel Kulesza's user avatar
0 votes
2 answers
71 views

Solving linear recursions without constant depth in mathematica

Mathematica does not like this recurrence relation. I do not understand why? ...
user26706's user avatar
3 votes
2 answers
603 views

RSolve with conditional equation

I have the following conditional equation: $f(n) = 1+2 f(n/2)$ when n is even $f(n) = 1+f((n-1)/2)+f((n+1)/2)$ when n is odd I want to represent this as a conditional equation to be used in ...
heykell's user avatar
  • 31
0 votes
2 answers
690 views

How to construct a linear feedback shift register

Are there any posts regarding the construction of a LFSR (Linear Feedback Shift Register) in Mathematica? I can't seem to find any and I am not sure how I would construct one.
connor's user avatar
  • 143
0 votes
1 answer
127 views

How to improve this function that selects parameters from arbitrary distribution using Recursion?

Below, I have defined a function using Which to select model parameters based upon various conditions. My questions are: Is there any danger in writing this function using Recursion? Is there a more ...
tarhawk's user avatar
  • 769
1 vote
2 answers
162 views

Solving Recurrence equation for n

I have a recurrence equation $t_n$ which is defined as $$ t_n=2.5t_{n-1}-1.5t_{n-4},\qquad \text{for }n\geq5 $$ Where $$ \begin{align} t_1&=5\\ t_2&=10.5\\ t_3&=26.25\\ t_4&=62.625 \...
user avatar
4 votes
1 answer
245 views

Modifying Game of Life code so that the lattice can be seeded with life forms

I want to modify Game of Life code so that the lattice can be seeded with one or two new life forms like: ...
user3550163's user avatar
0 votes
1 answer
195 views

Problem with recursion depth

I want to solve a problem where I need to compute the Euler-Lagrange equation. However I receive a recursion problem, and I don't understand why. ...
Carl's user avatar
  • 1

1
8 9
10
11 12
14