Questions tagged [recursion]

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

Filter by
Sorted by
Tagged with
2
votes
0answers
34 views

Why does this memoized function cause the kernel to quit?

The following memoized recursive function causes the kernel to beep and quit. ...
2
votes
1answer
31 views

Using NIntegrate inside RecurrenceTable

I'm trying to solve self-consistent equations of the form ...
1
vote
0answers
35 views

RSolve not evaluating when given my system of recurrence equations

I am trying to solve the following system of recurrences with RSolve: ...
0
votes
3answers
39 views

Recursive Function with conditionals [duplicate]

Function: I am to solve for $T_{12}(4.8), T_{24}(1.2)$, using If and Which functions. I started with this function and keep getting a recursion limit error: ...
5
votes
4answers
293 views

Recursive function, if and which statements

I am given this question: Let a function $ T_n(x) $ be defined by: $$ T_{n+1}(x) = \frac{1}{x} T_{n-1}(x) - \frac{2}{7} T_n(x), $$ where $ T_0(x) = 1, T_1(x) = x $. I need to construct a recursive ...
3
votes
0answers
86 views

Iterative process causing segmentation faults

Often in Mathematica, I program in some iterative process (say, some random walk) in order to find maxima. I usually write some hacky code involving iteration, and using the construction: ...
0
votes
0answers
28 views

Recurrence relation of coeeficients of power series solution to DE

Say I have a DE $$ -\phi \left(\phi \left(\left(6975 \phi ^2-3704 \phi +160\right) \omega '(\phi )+\phi \left(\left(6975 \phi ^2-4688 \phi +266\right) \omega ''(\phi )+\phi \left(2 \left(...
2
votes
0answers
30 views

Trace reveals unexpected evaluations and internal calls for recursive function

I would like some help in identifying the problem in my implementation of the recursive function shown below. But first, a bit of background. There is a well-known solution to the problem of finding ...
3
votes
3answers
99 views

how can I calculate $a_{n+3}=a_n+a_{n+1}+a_{n+2}$?

recently I need to calculate this: $a(n+1)=((a(n-2)+a(n-1)+a(n)) \bmod 10000)$ and get $a(20000000)$ (for example). I know RecurrenceTable,but ...
3
votes
1answer
45 views

Making a recursive function

Suppose I have the following functions: a[x_] := x b[x_] := x (a[x]) - a[x] + 1 c[x_] := x (b[x]) - b[x] + 1 d[x_] := x (c[x]) - c[x] + 1 as you can see each ...
5
votes
2answers
380 views

Using Table Recursively

I wonder if it's possible to create a list with Table from entries of the list itself. That is, as I'm creating the list, I append a new element as a function of ...
6
votes
1answer
121 views

Trying to find a better way to implement a recursive depth first search

I'm trying to implementa recursive depth first search. It works and the result is below: ...
1
vote
1answer
58 views

Solving a recurrence relation with constraints

I have the following recurrence relation with complex coefficients: c[n] == Sqrt[n-1] c[n-1] + Sqrt[n] c[n+1] I also have the constraint that $\sum_n |c_n|^2 = ...
5
votes
1answer
93 views

Solving partial recurrence equation with several recurrence indices

I'm trying to solve a recurrence relation for a function of three variables. It works with 2 variables but not with 3. A simple example is: ...
1
vote
1answer
43 views

Problem when using NMinimize in a RecurrenceTable

I have a problem when I'm trying to use NMinimize in my RecurrenceTable, like in this example : ...
0
votes
0answers
34 views

Getting the form of a recursively defined function [duplicate]

Here is my iterative relationship: ...
1
vote
0answers
54 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
139 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
39 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
80 views

How to assign a constant value in a recursion relation

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

Slow computation of recursive sequences

I want to investigate the asymptotic behavior of the following recursive system: ...
1
vote
2answers
55 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
102 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
64 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
43 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
84 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
225 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
101 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
154 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
120 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
83 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
92 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
141 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
34 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
74 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
57 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
42 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
145 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
48 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
54 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
56 views

Recurrence involving a product of recurrents

I can solve the following recurrence problem as follows: ...
-1
votes
1answer
62 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
128 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
95 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
85 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
141 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\...

1
2 3 4 5
11