Questions tagged [sequence]

Questions on specifying order in and splicing of lists, including use of Mathematica Sequence objects.

Useful Links:

191 questions
15
votes
4 answers

How do I test if a variable represents a sequence?

I created a variable that represents a sequence: mySeq = Sequence[1, 2, 3]; I wanted to use that variable as an argument for some functions. But I got in trouble. For example, FreeQ[mySeq, 1] generates an error message. So I wanted to test if…
Soldalma
  • 1,289
  • 1
  • 9
  • 17
8
votes
5 answers

How can I tally continuous sequences in a list?

I have a stream of data like this: 0001100111100000111111001110000001111111111000000111000111110000... (I can represent them as a list, like in {0,0,0,1,1,...}, I guess that's easier to work with.) Now I want to count how many sequences of two…
stevenvh
  • 6,866
  • 5
  • 41
  • 64
4
votes
4 answers

How to get Mathematica to show limit of a recurrence sequence?

I want to find the limit of a such a sequence: $f(n+1)=\sqrt{2f(n)-1}, \, f(0)=a, a>1$ How does one do this? Is it possible to have it show the solution algebraically, like it does with standard (non-recurrence) limits in WolframAlpha? (I wasn't…
4
votes
5 answers

Sequence generation

If I wanted to generate a sequence that follows the pattern $$x_{n}=x_{n-1}+\dfrac{1}{2}\left(\sqrt{1-y_{n-1}\ ^{2}}-x_{n-1}\right)\\ y_{n}=y_{n-1}+\dfrac{1}{2}\left(\sqrt{1-x_{n}\ ^{2}}-y_{n-1}\right)$$ rather than writing the whole thing out: x0…
martin
  • 8,678
  • 4
  • 23
  • 70
4
votes
1 answer

How can I find some first terms of a sequence?

I have a sequence knowing that $a_1=15$, $a_{n+1} = a_n + \sqrt{2a_{n+1}-a_n}$. I want to find some the first terms. I tried by my hand k := 15; Solve[x == k + Sqrt[2 x - k], x] {{x -> 20}} k := 20; Solve[x == k + Sqrt[2 x - k], x] {{x ->…
Thuy Nguyen
  • 909
  • 4
  • 11
4
votes
1 answer

Conditionally add an element to a list by using Apply to delay the Sequence until evaluation

Could you explain the details for the following code? foo[x_, y_] := {a, If[x === y, b, Sequence @@ {}]} foo[s, s] foo[s, t] Output: {a,b} {a} Why isn't the output as follows? {a,b} {a,}
Display Name
  • 2,009
  • 8
  • 17
4
votes
2 answers

Generate a sequence of sequences

Imagine I have a sequence of M integers each of which is either zero or one. How do I generate a sequence of all such 2^M sequences?
Quasar Supernova
  • 1,678
  • 8
  • 13
3
votes
2 answers

How to insert a list in the second argument of Table?

I wrote the following table: k = 4; T = Table[{a[n], 0, 1}, {n, 1, k}] Which generates: {{a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}} Now in the I want to use this in the next table: Table[Table[a[n], {n, 1, 4}], x] In a way that makes…
Red Banana
  • 5,329
  • 2
  • 29
  • 47
3
votes
0 answers

Find the second longest common subsequence?

I am trying to determine that how my sequence(probe) "hits" against a long sequence(genome). The LongestCommonSubsequence in Mathematica gives the first longest common subsequence between two sequences. Is there a good way to find the second…
Yordan
  • 311
  • 1
  • 4
2
votes
1 answer

Why is there such a problem with finding a formula for the general term of a sequence?

FindSequenceFunction[{1, 2, 5, 14, 41}, n] 1/6 (3 + 3^n) You can directly calculate the general term formula above Why is it impossible to find the general term formula below? In[1]:= FindSequenceFunction[{2^1, 2^2, 2^5, 2^14, 2^41}, n] Out[1]=…
csn899
  • 3,953
  • 6
  • 13
2
votes
1 answer

Generating a list of specific intermediate numbers associated with continued fractions

First of all, I don't know how ContinuedFraction[] or Convergents[] are implemeneted, and I think it is immaterial to my question. for some number $x$ there's an associated continued fraction representation $[a_1,...,a_i,...]$ (finite or not), and,…
user76568
  • 401
  • 1
  • 4
  • 13
2
votes
2 answers

Alternatives to Sequence[] as a nonexistent expression element

I stumbled upon this code by Leonid Shifrin. He uses Sequence[] to create void or non-existent output. I was wondering whether this is really the best way to generate non-existent output in that way? What are alternatives? I was looking for a…
GambitSquared
  • 2,311
  • 15
  • 23
2
votes
3 answers

Using a piecewise defined sequence, find all $x_0$

Given $0\le x_0<1$, let $$x_n=\begin{cases} 2x_{n-1}, & \text{if $2x_{n-1}<1$}\\ 2x_{n-1}-1, & \text{if $2x_{n-1}\ge 1$} \end{cases}$$ for all integers $n>0$. For how many $x_0$ is it true that $x_0=x_5$? The answer is supposedly 31. Does anyone…
David
  • 14,883
  • 4
  • 44
  • 117
1
vote
4 answers

Find a sequence given the sums of its terms

For a certain sequence of numbers, the sum of the first $n$ numbers in the sequence is given by $n^3+4n$ for all positive integers $n$. What is the fifteenth number in the sequence? How do you solve this problem the most efficient way?
1
vote
2 answers

Plotting non-linear recursive sequence

I'm a total noob with Mathematica, and while trying to plot the following, I get several error messages. What am I doing wrong? O[n_] := O[n] = 0.7*O[n - 1] + 0.002*O[n - 1]*M[n - 1] ; M[n_] := M[n] = 1.2*M[n - 1] - 0.001*O[n - 1]*M[n - 1] ; O[0]…
Walter U.
  • 297
  • 1
  • 8
1
2