Questions tagged [recursion]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
33 views

Getting NSum to go to the right depth in recursive definitions

I wanted to produce some plots of the action of the Gauss shift map on cumulative distribution functions. This means I wanted to plot functions $F_n(x)$, for $0 \leq x \leq 1$, defined by $F_1(x) = x$ ...
-2
votes
2answers
115 views

Find the square root using a recursive formula [closed]

I want to approximate the square root x=Sqrt[a] for $a>0$ using the the formula $x_{n+1}=\frac{1}{2}(x_n+a/x_n)$. How can I do this?
2
votes
1answer
37 views

RecurrenceTable: numercial exception

When I added vector b into expression, it returned with RecurrenceTable::excptn: Value {2/3,-(1/3),2/3,-(1/3)} is a numerical exception. ...
1
vote
2answers
77 views

How to assign a constant value in a recursion relation

I use the code ...
4
votes
3answers
409 views

Slow computation of recursive sequences

I want to investigate the asymptotic behavior of the following recursive system: ...
1
vote
2answers
54 views

Mistake in recursive algorithm

I am new to Wolfram, and I am trying to make a recursive Archimedes algorithm in Wolfram. I read documentation and I tried to run this code ...
1
vote
2answers
83 views

Implement a recursive formula with internal sum

I need to calculate following recursion formula. I implemented this in MATHEMATICA as follows: But it always gives errors for $k>0$. Can someone help me to implement this? ...
3
votes
2answers
58 views

What is the fastest way to calculate series from recurrence solutions with no closed form?

I am not very experienced with Mathematica. I want to calculate the series from recurrence solutions. These solutions have no closed-form. I want to improve the approximation and hence need a good ...
0
votes
0answers
35 views

How to convert a symbolic recursive formula to a non-recursive one

I am new to Mathematica. I want to convert a recursive formula to a non-recursive one using symbolic math. Specifically, I have a recursive formula similar to this: $a_n = f_a(c_{n-1}, x_{n-1})$ $...
5
votes
1answer
77 views

Recursive nesting with parameter

I would like to apply a function f recursively to an expression expr an arbitrary number of times. However the catch is that <...
0
votes
1answer
46 views

Generating a Large (possibly infinite list) of Formulas From A Group

Here's a little background, I have a finite list of linear formulas in 6 variables and 6 linear transformations in these variables. Obviously I can apply these transformations with /. to my current ...
3
votes
1answer
68 views

Looping routine to evaluate a recursively defined function

I'd like to do a calculation which is basically a looping routine to evaluate a recursively defined function. For example: ...
4
votes
4answers
210 views

Programming a recursive formula into Mathematica and find the nth position in the sequence

Well, I have the following recursive formula (where $\text{n}$ gives the position in the sequence): $$\text{P}_\text{n}=\alpha\cdot\text{P}_{\text{n}-1}+\text{P}_{\text{n}-2}\tag1$$ For arbitrary $\...
3
votes
1answer
87 views

Recursive solution to the extended Josephus problem [duplicate]

The Josephus Problem is described here, with extension of killing every $k$th problem. In the simple case where every other person is killed, we can also use the binary trick. ...
4
votes
2answers
137 views

Trying to build a function to compute divided difference for arbitrary list of points

As the title says Im trying to build a function to compute divided difference for arbitrary list of points. The divided difference of a set of points $\{(x_1,y_1),\ldots, (x_n,y_n)\}$ where $x_j<...
0
votes
1answer
47 views

Recursion problem with output

I wrote the following recursion, assuming that the function would gradually decrease the size of list k by 1 (via Drop). Reap and Sow indicate that a different output is produced. I do not immediately ...
2
votes
1answer
118 views

Most efficient code for a recursion relation

What is the most efficient code for the following formula: $y_{n+1}=\frac {2y_n-y_{n-1}+5g_n y_n+g_{n-1}y_{n-1}}{1-g_{n+1}}$ where $g_n$ is a variable. I have tried this code ...
0
votes
1answer
78 views

How to get solutions for recursive relations using RSolve?

I have $$a(x,t+2) - a(x,t) = -\cos{\theta} [a(x+1,t+1) + a(x-1,t+1)]$$ Setting $t' = -t\cos(\theta)$ fetches under the continuum approximation $$2 \frac{\partial a(x,t')}{\partial t'} = a(x-1,t') - ...
0
votes
2answers
83 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 ...
2
votes
3answers
116 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 ...
0
votes
1answer
32 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
69 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
54 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
39 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
144 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
41 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
48 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
52 views

Recurrence involving a product of recurrents

I can solve the following recurrence problem as follows: ...
-1
votes
1answer
55 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
103 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
85 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
80 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
116 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
83 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
240 views

How to increase the accuracy of a plot

I have the following code below: ...
2
votes
1answer
84 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
73 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
94 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
87 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
131 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
88 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
334 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
74 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
107 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
89 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
59 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
110 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 ...
2
votes
1answer
118 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 ...