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

learn more… | top users | synonyms

9
votes
1answer
126 views

Maximizing a recursive functional equation

I would like to maximize a recursive functional equation but I am struggling with setting up the problem correctly. The equation I am interested in captures the nature of a decision process over time ...
0
votes
0answers
11 views

recursion over $\arg \max$ function [migrated]

I want to find a recursive/incremental update of the following equation: $\qquad d^{(n)} = \arg \max_{d=0:\,D-1} (s \cdot d + \sum_{i=1}^{N} f(x_i,d))$ where $d^{(n)}$ is the dimension number, $s$ ...
1
vote
1answer
60 views

I can not solve this equation for recurrence [closed]

Use RSolver to solve RSolve [{f [n + 1] == f [n] + 2 n + 1, f [1] == -3}, f [n], n] but I do not get solution Edit my solution
2
votes
1answer
216 views

Speeding up this recursive function

I have a recursive function defined like this: ...
3
votes
3answers
119 views

Limit n->Infinity of recursive sequence

I have defined a recursive sequence a[0] := 1 a[n_] := Sqrt[3] + 1/2 a[n - 1] because I want to calculate the Limit for this ...
10
votes
2answers
277 views

How to “inform” successive ContourPlot calculations?

I need to draw some contour plots of very non-linear functions. As a simple example, take a Mandelbrot Set divergence contour near $z\approx i$. (Just to be clear, I'm not trying to write a ...
1
vote
3answers
40 views

cantor set intervals

I have been trying to figure out how to get the values for the limits of the Cantor set intervals (see here). The formulas that i could find only gave the interval themselves but what i need is only ...
3
votes
3answers
152 views

What's wrong with this while loop index definition?

For[k = 1, k < 4, k++, T = Table[i^2, {i, 0, k}]; f[k] = T; ] In the above, I wish to define a function $f$ by $f(k)=\{0^2,...,k^2\}$ for $k=1,2,3$, but the ...
5
votes
4answers
242 views

Calculating N-th step of recurrent sequence

I am figuring out how to calculate $N$-th step of a square root approximation sequence: $$x_{n+1} = {1 \over 2} (x_{n} + a/x_n),$$ where $a$ is a number the root of which is to be found and $x_1$ is ...
4
votes
1answer
102 views

Find random $n$ combinations of values with a given sum

This problem is described in the related StackOverflow question: Find all combinations of coins when given some dollar value. I would like generate a list of $n$ combinations of values that sum up to ...
2
votes
1answer
112 views

Problem with implementing Regula Falsi [closed]

I checked the "Questions that may already have your answer" and didn't really find what I need. It's actually pretty basic. I want to solve an equation manually with Regula Falsi. I dont need a ...
1
vote
2answers
58 views

Floor function issue [closed]

While attempting to evaluate a recurrence relation an error with the Floor function is encountered. Computing an example to verify the floor function works correctly I ran the code ...
3
votes
1answer
87 views

Extreme Slowdown with Fold

I am doing a finite difference model, and need to create a list recursively. For a small list, Fold is extremely fast, but when the list becomes large enough, Fold becomes extremely slow. Here is the ...
1
vote
0answers
45 views

recursion and if-statements

So im trying to write a recursion module in mathematica (specifically for strassen multiplication but this doesn't matter). My issue is I don't really know how if statements work in mathematica and if ...
0
votes
1answer
29 views

Modify code to avoid recursion limit warning [closed]

I programmed a recursive function and I want to see the evolution depending on the number of trials. I want to find the value of k for which the difference between $rec_i^k$ and $rec_i^{k+1}$ is equal ...
2
votes
0answers
40 views

Convergence of a recursive function

I am trying to study the convergence of a function that is defined by recursion. We want to find for which 'j' the difference between $ g_i^j $ and $ g_i^{j+1} $ is equal or smaller than $10^{-3}$ . ...
1
vote
1answer
72 views

Define recursive function over two indices

I have $x_i=(i-1)/50$ for $i=1,\ldots,51 $. Given a function $ f(x) = x^2 $, I want to find $y_i^k$ given by \begin{eqnarray} y_i^1 &=& f(x_i) \\ y_i^{k+1} &=& ...
2
votes
0answers
45 views

Why doesn't RSolve work here? [closed]

RSolve[ {θ[n + 1] == θ[n] + 0.25*ϕ[n], ϕ[n + 1] == ϕ[n] - 2.5*Sin[θ[n]], θ[0] == π/2, ϕ[0] == 0}, {θ[n], ϕ[n]}, n] What's wrong with my code? I know ...
7
votes
3answers
205 views

Deleting any list that contains a negative number

We had another nice question in a student activity today. The increasing sequence of positive integers $a_1,a_2,a_3,\ldots$ has the property that $$ a_{n+2}=a_n+a_{n+1} \text{ for all } n\ge 1. $$ ...
6
votes
2answers
612 views

How does one clear the memory of a recursive function

I want to implement the recursive function v[n_] := v[n] = v[n-1] + f[n-1] + Random[NormalDistribution[0,s]] to get ...
6
votes
4answers
273 views

Iterating a rational function

I'm reading about iterating rational functions. I'm given $$R(z)=\frac{3z-2}{2z-1},$$ then the author makes the statement: "Then(by induction), $$R^n(z)=\frac{(2n+1)z-2n}{2nz-(2n-1)}.$$ Is there a ...
2
votes
0answers
41 views

Why does this form of piecewise function cause a general stop message? [closed]

I am currently learning about Mathematica by reading the book Mathematica by Example, 4th Edition. In that book, a piecewise function was defined as follows: ...
4
votes
2answers
74 views

Assigning function values in a memoized recursive module

I have a complicated recursive module which I have memoized. I realised that certain isomorphs of inputs to this function will give the same output. Therefore I decided to memoize all such ...
3
votes
1answer
52 views

FindLinearRecurrence is not working for numerical complex number sometimes?

First FindLinearRecurrence definitely support complex number list, see ...
5
votes
4answers
202 views

Recursive piecewise integral relation with piecewise base case?

How is this recursive formula $$ f_{n+1}(z) = \int_0^1 f_{n}(z-y)\,{\rm d}y $$ implemented in Mathematica? The base case is $$ f_1(z) = \begin{cases} 1 & 0\leq z\leq 1 \\ 0 & ...
2
votes
2answers
162 views

Solving problem using recursive functions

Attached below is a question posed by the Canadian Mathematical Society, and I have my code and answer. Is there a better way of writing the code, and will the answer be different as a result? My ...
18
votes
6answers
788 views

Recursively appending elements to a list

In wanting to demonstrate the power of Mathematica, I wanted to show my 11-year-old son how we could validate that his sequences homework was correct. We could generate the next value in sequence in a ...
3
votes
2answers
73 views

How do I determine the 15th Lucas term in the 3rd order?

I want to implement the Lucas n-Step Number. This command taken from here doesn't seem to work, am I using the right command? ...
7
votes
2answers
121 views

Recursive function activity

We had the following question on an activity for our students: Let $f_0(x)=x+|x-100|-|x+100|$, and for $n\geq 1$, let $f_n(x)=|f_{n-1}(x)|-1$. For how many values of $x$ is $f_{100}(x)=0$? When I ...
10
votes
9answers
1k views

How can I make a Tribonacci sequence in the form of a list?

How can I make a Tribonacci sequence that is in listing form? it suppose to look like the Fibonacci sequence but I couldn't get ...
7
votes
2answers
233 views

How to compile self-referencing functions (to perform recursive a task)

How do I compile a self-referencing function to perform iterative tasks? The naive approach doesn't seem to work. Here is a simple example to illustrate the problem: ...
1
vote
0answers
27 views

Why am I getting this “recursion depth” error message? [closed]

I am simply trying to use this command p[1,2][1]/.{p[x_,y_][m_]:>pp[x,y][m]} and I'm getting an error message ...
5
votes
2answers
70 views

Solution to Simultaneous Arithmetic/Geometric Mean Recursion Relations

I'm trying to solve the simultaneous convergent sequences of geometric/arithmetic means where $a_{n+1}=\frac{1}{2}(a_n+b_n)$ and $b_{n+1}=\sqrt{a_nb_n}$ and initial values are $a_0=1+x$ and $b_0=1-x$. ...
2
votes
1answer
84 views

Problems with multidimensional system of ODEs

I am trying to look at the migration of "i" number of species "c" in "10" number of habitats {designated as "j"} and to study their population size as a function of time "t". I have this following ...
2
votes
1answer
77 views

how to write generic equation for Recurring differential equations?

Hi I am a biologist and I want to model some ecological data that I have. I am new to mathematics and to ODEs. I want to write generic equations for a multi-dimensional system of ODEs. So, I want to ...
3
votes
2answers
210 views

How do you create matrices using submatrix building blocks?

Here is a conundrum I am facing. I have $2$ matrix building blocks. In my problem, I associate integer $2$ with $3\times 3$ matrix $A$ with structure \begin{bmatrix} 0& a& 0\\ c& 0& ...
1
vote
1answer
90 views

Recursive calculation is very slow

I've got a recursive definition of Arcs that shares equal length and a several other dependencies to each respective predecessor. (Imagine a book being bent.) I formulated all necessary things here: ...
1
vote
1answer
49 views

Solution of recursive equations with FixedPointList

I want to solve an equation numerically for given starting values, then evaluate 3 integrals for this solution, set the results to the new starting values and iterate until the result converges. Here ...
4
votes
0answers
92 views

Optimization of recursive functions by using the //. operator [duplicate]

In some cases, recursion in Mathematica (without storing values) is not very efficient. For example, the recursive implementation of Fibonacci numbers (version which doesn't store the values) : ...
1
vote
1answer
60 views

Solving recursions

This question is tied to my previous question. I have a few recursion formulas, and I keep getting Recursion depth of 1024 exceeded. error. I need to get the ...
4
votes
0answers
73 views

Method of characteristics, recursion formulas

I'm helping a friend out with a problem. He needs to plot out the solution to a water surge in a pipeline. I have all the parameters set and I've put the equations in Mathematica, but I can't get the ...
12
votes
3answers
243 views

How to implement a more efficient inverse triangular recursion?

Consider the following inverse triangular formula $$\left( \begin{array}{ccccc} & & & & N_{i-p,p}\left(u_0\right) \\ & & N_{i-2,2}\left(u_0\right) & & ...
4
votes
1answer
112 views

Recursive list contruction

I am attempting to implement the exercises from The Little Schemer in Mathematica, and running to a bit of a challenge with rember (remove member). Given a list and a value, the function just returns ...
4
votes
1answer
75 views

Fishing for monomials in a nested or partially factored polynomial stream

I have a problem where I'd like to be able to take a multivariate polynomial whose variables are nonscalar and is not written explicitly as a sum of it's nonzero monomial terms and determine which ...
6
votes
3answers
511 views

Implementing Picard's Iteration for solving ODEs

Picard's Iteration is a way of solving the IVP $$y'(x)=f(x,y(x)), \quad y(x_0)=y_0 $$ It consists of defining the following sequence of functions recursively: $$y_0(x):=y_0 \\ ...
5
votes
2answers
66 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 ...
2
votes
1answer
65 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 ...
2
votes
2answers
138 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: ...
9
votes
1answer
96 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: ...
18
votes
4answers
829 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 ...