Questions tagged [recursion]

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

0
votes
2answers
75 views

Getting the coefficients of a series that solves a differential equations

I have an example from Stewart's Calculus where the equation $y'' + y = 0$ is solved using power series. The equation ...
1
vote
3answers
77 views

Sum with variable terms to sum over

Suppose I have a polynomial like this: $$a=x_{j_1} + x_{j_1}x_{j_2} + x_{j_1}x_{j_2}x_{j_3} + ...+x_{j_1}x_{j_2}x_{j_3}...x_{j_n}$$ I want to create a function that takes this polynomial and does the ...
-1
votes
0answers
111 views

How to make this function optimized?

How can I optimize the recursive function GMulEnt in order to make a faster calculation? ...
0
votes
1answer
29 views

Constructing sequence of function with elements depending on the previous one / recursion

Starting from a function $\theta0[x\_ , y\_ , z\_ ]$, the terms $\varphi[x\_ , y\_ , z\_ ]$ constitutes a sequence of functions that is constructed as follows: Order 1 (one function and its ...
1
vote
2answers
55 views

Computing recursive sequence [duplicate]

I would like to compute a[1000] of the following recursive sequence a[1] = 1; a[n_] := a[n - 1] + 1/a[n - 1]^2 but it takes a long time for computing even small ...
2
votes
3answers
49 views

Defining recursive non-linear recurrence relation

I have a non-linear recurrence relation: $$\epsilon_i = \sqrt{\frac{2}{1+\epsilon_{i-1}}}\epsilon_{i-1}$$ Here, $\epsilon_0\in[0,1]$, but it's really some function $f(n,p)$ for some other parameters. ...
1
vote
1answer
27 views

Trouble with RecurrenceTable using elements from a previously computed list

When I use RecurrenceTable to solve a recursion relations, I encounter a problem, which is perhaps simple, but I do not understand why it is complaining. Here is a ...
1
vote
3answers
135 views

Why doesn't Mathematica evaluate the series with recursion relationship as expected?

I define a series $dg(i)$ as the $i$th derivative of a function $g[t]$ for $i>0$ and known the first term $dg(1)=(t-x)g(t)$. In mathematica, the code is: ...
1
vote
2answers
35 views

RecurrenceTable of a piecewise recurrence function

How to can I get RecurrenceTable to deal with a piecewise function? For example, $ \qquad x_{n+1}= x_n(1.5-0.5x_n)\qquad \text{if $x_n\ge0.5$}\\ \qquad x_{n+1}= ...
3
votes
1answer
35 views

RecurrenceTable involving inputs from a vector

Directly going to the issue, my problem is how to use a RecurrenceTable when it have inputs from a vector defined previously. For instance I have: ...
0
votes
1answer
40 views

Recurrence involving a product of recurrents

I can solve the following recurrence problem as follows: ...
-1
votes
1answer
51 views

Error when Solving Recurrence Relation

I would like to analyze the following recurrence relation. $r_i = r_{i-1} - \frac{1}{2} \cdot \sqrt{1 - \frac{4\pi^2\cdot r_{i-1}^2}{n^2}}$ $r_0 = \frac{n}{2\pi}$ I have implemented this as ...
0
votes
1answer
72 views

Recursive Function in Multiple Variables

I can define a recursive function in one variable, e.g. defining the factorial function $f(n)= n!$ using Mathematica. But how do you do this for a function which depends not only on $n$ but on $x$ and ...
0
votes
2answers
78 views

Problem with a simple recursive function

f[2 x_] := f[x] f[1] := 3 f[0] := 0 f[2 x_ + 1] := f[x] + f[x + 1] a[x_] := f[x]/f[x + 1] Will this work as an recursive function ? I think there's something ...
5
votes
1answer
2k views

Why is this recursive code so slow?

This code for the first five iterations the speed is okay, but after that the speed is very slow, I cannot understand what is wrong with this? Would you please help me fix it? ...
0
votes
1answer
76 views

How can I use Compile to implement recurrence?

I am trying to make the code for the following recurrence. Here wjoin[[i]] is used for calling values from a data set and a is a ...
2
votes
1answer
89 views

Solving for the recursion relation for the expansion coefficients of the asymptotic expansion of an ODE

I want to solve for the asymptotic solution of the following differential equation $$ \left(y^2+1\right) R''(y)+y\left(2-p \left(b_{0} \sqrt{y^2+1}\right)^{-p}\right) R'(y)-l (l+1) R(y)=0$$ as $y\...
2
votes
3answers
75 views

Indexed function recursion problem

I am trying to use indexed functions in a For loop; to illustrate, I give a trivial example. f[1, x_] := x^2 Now, I can define: ...
0
votes
1answer
39 views

Help with recurrence relation

I try to solve the following recursion for $n \in \mathbb{N}$. $r_i = r_{i-1} - \frac{1}{2} \cdot \sqrt{1 - \frac{4\pi^2\cdot r_{i-1}^2}{n^2} \cdot \cos^2 \left(\frac{\pi}{n}\right)}$ $r_0 = \...
3
votes
1answer
181 views

How to increase the accuracy of a plot

I have the following code below: ...
2
votes
1answer
78 views

My version of PowerMod breaks down around 10^308

I have been trying to write a function that duplicates PowerMod[a, b, n], computing a^b mod n...
0
votes
1answer
59 views

Update initial conditions recursively/sequentially within ParallelTable using NDSolve

I am modelling 3D motion of particles inside a force-field using second-order coupled PDEs, which I solve from time t=t0 to t=t1 with initial conditions x0,y0,z0. I have a total number of "particles" ...
2
votes
3answers
86 views

Defining a recursive function with additional parameters that can be used in a Manipulated ListPlot

I'm trying to code up some plots for Autocorrelation Functions in Time Series Analysis, which can often be defined recursively. The goal is then to have Manipulate sliders that allow you to ...
1
vote
1answer
83 views

A program for finding the summation of an analytical expression

Consider the Baker-Hausdorff formula for two operators $A$ and $B$: $$e^BA e^{-B} =A+[B,A]+\frac{1}{2!}[B,[B,A]]+\frac{1}{3!}[B,[B,[B,A]]]+....,$$ where $[A,B]=AB-BA$. In the case of my problem, $[B,...
1
vote
1answer
91 views

Why are there local variable conflicts in my recursive function definition?

Sorry to post a long piece of code. There are two places in here where I Print[] 'path2' when the count == 984, because for some reason, that list is getting ...
2
votes
1answer
75 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 ...
5
votes
7answers
330 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
69 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 $...
1
vote
1answer
101 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
68 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
105 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
52 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
74 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
89 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
43 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? ...
6
votes
1answer
125 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
39 views

RSolve for three arguments

I would like to find the general expression for a recursive equation: ...
0
votes
1answer
52 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
31 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
55 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
136 views

RSolve not reducing for a certain recurrence relation

I'm trying to use RSolve as follows to solve a recurrence relation: ...
1
vote
0answers
37 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
33 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
52 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
35 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 ...
0
votes
1answer
173 views
6
votes
2answers
495 views

Applying a recursive function to a list to get another list

Here is a list: ...
0
votes
0answers
37 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 ...