Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [recursion]

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

1
vote
1answer
41 views

a recursive function using memoization

I have looked at a lot of these cases, e.g. Can one identify the design patterns of Mathematica? and the included ones. My trimmed example, here establishing the 'initial conditions' (where the ...
4
votes
7answers
278 views

Computing only Prime Powers with NestList

Is there a simple way to compute only prime powers of a function f with NestList? That is, I want to compute: {f[x_0], f^2[x_0]=f[f[x_0]], f^3[x_0], f^5[x_0]...} ...
0
votes
2answers
57 views

Implementing the factorial rule

I want to implement a command in Mathematica in order to simplify factorials in the following way $$(n+x)!=(n+x)(n+x-1)\cdots n!$$ I started to build this up slowly. I have managed to implement $...
0
votes
0answers
44 views

Solving system of differential equations in loop with recursive variable

I've been posting various questions about similar pieces of code all year, so if this looks familiar you may have seen another one of my posts, but this is a unique issue that has not been asked yet, ...
1
vote
1answer
92 views

Speeding Up Recursive Evaluation

I have a recursive function for which I need the values for n=1 through about n=100,000,000 (or more). The function looks as follows, with output of the form ({x,y},a), and f, g, and h some functions. ...
1
vote
1answer
51 views

RSolve and a Piecewise Recurrence + Runtime

This should really be a comment to this answer but I don't have enough rep. I'd like to know how to do the same thing (efficiently - see below) but with $\mod 3$ conditions, i.e. define a[k] to be the ...
-1
votes
1answer
57 views

Is there a way to get values from a set of functions with circular dependencies? [closed]

I am using the following code to find iteratively the functions $\Sigma(r)$, $h(r)$ and $T(r)$ ...
1
vote
2answers
97 views

Creating an Excel-Like Recursive Function

I'm trying to create a certain "excel-like" recursive function, which runs through a pre-defined list and performs an operation dependent upon the current position (similar to the "drag down" type ...
1
vote
1answer
27 views

Mathematica code for computing the $p$-adic expansion of rational numbers

Does anyone know any Mathematica code for computing the $p$-adic expansion of rational numbers? I.e. given a rational number $a/b,~a,b\in \mathbb{Z}$ and a prime number $p$, then compute the $p$-adic ...
0
votes
1answer
69 views

Finding a sequence with RecurrenceTable

I would appreciate if somebody could help me with the following problem: Q: How can the following recursion equations be solved using RecurrenceTable? $\...
1
vote
2answers
46 views

How to define a recursive sequence

I would appreciate if somebody could help me with the following problem: Q: How to define this in Mathematica. $$a_{n+1}=\begin{cases} a_{n} & ,a_{n} \ge n\\ 2n-a_{n}& ,a_n<n \end{cases}...
1
vote
0answers
36 views

Recurrence that contains Sum of previous elements

I would like to create the recurrence that contains the summation of all previous elements, but it seems it does not work. That I'm doing wrong? ...
5
votes
1answer
118 views

Recycling solutions of multidimensional NDSolve

Dear wolfram community, I hope my problem is clear and easy to solve. I have already solved the following heat equation over a domain: ...
1
vote
1answer
35 views

RSolve for three arguments

I would like to find the general expression for a recursive equation: ...
0
votes
1answer
43 views

Plotting intermediate values of an argument in a recursive function

I've read through the documentation on tuning and debugging but feel like I am missing some important concepts. Many of the examples given presume the programmer is explicitly generating ranges of ...
0
votes
1answer
28 views

Exponent Recursion implementation

I want to implement this recursive formula: "j" is imaginary symbol (i.e. j = I = Sqrt[-1]); I have written my code as: ...
2
votes
2answers
53 views

Expand a recursion relation

Hermite Polynoms have the following recursion relation: $$ H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x), $$ which can be rearranged to be $$ x H_n(x) = \frac{1}{2} H_{n+1}(x) - n H_{n-1}(x).$$ Is it ...
0
votes
1answer
35 views

Recurrence Relation with two variables and boundary conditions

I try to express the following recurrence relation in Mathematica: I am very sorry but for any reason I am not allowed to embed math code here... \begin{align*} x_{1,t} &= \frac{1}{2} x_{1,t-...
4
votes
2answers
97 views

RSolve not reducing for a certain recurrence relation

I'm trying to use RSolve as follows to solve a recurrence relation: ...
0
votes
0answers
30 views

Recursive function call in Fold: $RecursionLimit issue

I'm trying to generate a list of all local complements of a graph $G$. A local graph complement $G\star v$ for $v\in V$ is defined as taking the neighbourhood of the vertex $v$, and flipping the ...
1
vote
1answer
32 views

How to perform a set of commands specific amout of time?

I have 3 lines of code that does the Collatz Conjecture in mathematica. the code is the following: ...
1
vote
0answers
49 views

ConditionalExpression still resulting from Assuming a Module's local variables

I have a memoizing, recursive function whose MWE looks like this (the two fake inputs/ICs are from 'K' and 'Bfun2', the latter just a quick way to check the results coming out of the Residue.: ...
1
vote
1answer
27 views

Getting error RSolve::dsfun [closed]

I an trying to solve a recursive formula and find the explicit representation of $a$. $a_0 = 1$ $a_{n+1} = 3 \sum\limits_{i=0}^{n} a_i$ When I evaluate ...
6
votes
2answers
481 views
0
votes
0answers
30 views

Recurrence Relation based on Vectors

I am new to Mathematica. I try to solve a recurrence relation based on vectors. So a[n] is a vector for all n (as well as ...
1
vote
0answers
80 views

Solving a recurrence relation with variable coefficients

I am trying to solve this recurrence inequality for $ a_n $, hopefully in terms of $ a_0,a_1,c $ and $ x $, $$(1-x)a_{n+1} \le xa_n + (1+x)a_{n-1} + c\quad\forall\ n\ge1$$ What I tried: RSolve. But ...
0
votes
0answers
31 views

Avoid Recursion in lag and difference operations

I have a panel data situation and I'm interested in taking lags and differences and using Mathematica to simplify the algebra of the result. Currently I'm working with a model like this: ...
7
votes
2answers
697 views

Simple Fractal square

I am working on a math question about infinite series, and one of the question images is below. Each new white square has an area that is 1/4 of the previous square. Always looking to learn elegant ...
1
vote
3answers
82 views

Unable to implement bisection method using recursion [duplicate]

I have tried to implement a bisection method for finding roots using SetAttributes[BisectionItt, HoldAll] and then ...
2
votes
1answer
71 views

Unwanted Hold from recursive function

I am literally copying an example from a tutorial in Mathematica documentation of a recursive function, but when I evaluate I get a Hold. I don't understand why I ...
1
vote
1answer
79 views

How can I implement a repeating operation?

I have the list: ...
1
vote
1answer
74 views

How do I define a function that uses a recurrence relation? [duplicate]

I know how to define functions other than the ones that use a recurrence relation to calculate the $n$-th term of a sequence. How would such a function be constructed?
1
vote
1answer
91 views

Definition of a recursive formula

For a given $n$, I would like to calculate a function $f_n$ recursively. Here is what I have: ...
0
votes
3answers
80 views

Understanding recursion and role of replacement rule for recursion in Mathematica

From the book "Essentials of Programming in Mathematica" (Fibonacci numbers): If we think of this sequence as a function, we would just change this to a functional definition. F(1) = 1 F(2) =...
4
votes
1answer
77 views

TracePrint does not work as in my book

I am using Mathematica 11.3 Here is an my execution of code from book "Essentials of Programming in Mathematica" (Fibonacci numbers): ...
4
votes
1answer
314 views

Tree-like data sets with efficient storage and retrieval

Most probably this is going to be a duplicate, sorry. I found too many questions/answers here about tree-like structures, and still could not locate what I want. It is a followup of my previous ...
3
votes
3answers
148 views

Generalisation of a generating function

I have asked a question here. I want to reproduce the coefficients of a generating function of the form: $$(1 + x)^2 (1 + x + x^2 + x^3+\cdots+x^n)^{n-1}$$ It is important that $x_0$ and $x_n$ to be ...
6
votes
1answer
91 views

Clever caching of a recursively defined function

I've got a function of the form f[n,s] where n is a natural number and s is a finite ...
5
votes
3answers
92 views

Constructing possibilities of a generating function

I want to find all the possible ways that 4 variables can be summed to a given number. Suppose I have the variables $$x=x_0+x_1+x_2+x_3$$ I want to fill $x_0,x_1,x_2$ and $x_3$ such that $x_0$ and $...
3
votes
1answer
135 views

Taking a long time to produce output

In the following, I want to know b[1000], but it is taking a very long time even for b[30]. Please help ...
1
vote
1answer
83 views

How can I optimize this short code?

I wrote two versions of this code which have similar performances. I'd like to know if it is possible to further optimize this code: ...
0
votes
1answer
59 views

Testing a description of the Cantor ternary set

The Cantor ternary set (aka the Cantor discontinuum) is, as usual, the set $K = \bigcap_{n=0}^{\infty} K_{n}$ where $K_{0} = [0, 1]$, the closed unit interval, and where for each $n \geq 1$ the set $...
0
votes
1answer
65 views

Recurrences with some relation to Dedekind eta functions

Dedekind eta functions are know to satisfy certain difference equations/recurrence relations. The same is true for ratios of eta functions. Suppose some ratio of eta functions, say $A(q)$ satisfies ...
3
votes
1answer
204 views

Recursion with substitution mathematica

When writing out some mathematical equation like we see on the picture here I got the problem of writing out all terms. I know what recursion means and have done recursion for example for the ...
8
votes
3answers
200 views

Using Total inside the RecurrenceTable

I would like to perform an operation over IntegerDigits recurrently. The operation is the sum of cubes of the digits, for example: $12 \rightarrow (1^3 + 2^3) = 9$...
7
votes
1answer
151 views

How to generate optimal solution and order the rest

This is a decimal maze, you start with 100 points and you must choose the path that gives you the highest score. Rule: You should not go twice for the same point and the same segment. My question: Is ...
1
vote
0answers
53 views

Recursive functions with integrals/derivatives return wrong results

I have the following recursive functions: ...
4
votes
5answers
422 views

How to solve the general formula by the recursive formula in MMA?

I want to solve this problem $T(n)=\sum_{i=1}^{n-1} 2T(i),T(1)=1$, I want to know how to solve this in MMA? My thinking: I have tried RSolve command, but the ...
1
vote
0answers
77 views

Problem with Wick Contraction

I'm trying to compute wick contractions knowing that: $\langle a_a a_b \rangle = \delta_{ab}$. So far I've the following ...