Questions tagged [sequence]
Questions on specifying order in and splicing of lists, including use of Mathematica Sequence objects.
190
questions
4
votes
1
answer
98
views
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
...
2
votes
1
answer
90
views
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 ...
0
votes
2
answers
92
views
Generating sequence from a number with Precision
This question was from the End-Semester question paper of the previous year of my Course on Wolfram Mathematica - Apparently when I try to code it, something is going wrong with respect to Precision - ...
6
votes
4
answers
413
views
Subdivide a sequence
Yesterday I couldn't solve a problem which seemed to be rather simple. I tried RepleaceRepeated, SequenceReplace and similar ...
20
votes
6
answers
826
views
Peaks, plateaus and ledges
I want to find the peaks, plateaus and ledges of an integer sequence, but all my attempts failed.
1. Example list
...
5
votes
4
answers
181
views
Joining constant arrays determined by a subsequence of contiguous block of ones
I have the following:
data = {15, 25, 35, 45, 55, 65, 75, 85, 95, 105};
selector = {0, 1, 1, 0, 1, 1, 1, 0, 0, 0};
I want to create the following list from ...
9
votes
6
answers
1k
views
How can I define a sequence of Integers which only contains the first k integers, then doesnt contain the next j integers, and so on
I need a list of integers to check if a variable has one of the values of the list.
If[ MemberQ[List,x], Green, Red]
The list contains integers and is characterized ...
1
vote
1
answer
62
views
Why doesn't Sequence@@ work inside Manipulate[]?
I'm trying to use Manipulate[] and I need to have a non-fixed amount of sliders.
I tried writing something like:
...
1
vote
0
answers
38
views
Sequence reconstruction from ordered subsamples
Given a sequence (we'll assume of integers) like
seq = {1, 0, 0, 1, 2, 0, 1}
I can take a random permutation
...
6
votes
3
answers
292
views
Split list into ascending sublists
I would like to split a list into non-overlapping, ascending (more precisely, non-descending with ≤) sublists. The function would be close to LongestOrderedSequence,...
4
votes
3
answers
213
views
Find shortest subsequence
We will deal with arrays of chars, but not strings!
Let we have the next three arrays:
...
0
votes
1
answer
41
views
Derivative with respect to a sequence
I want D[Subscript[a, k],Subscript[a,j]] to return something like the Kronecker delta. Is this possible?
2
votes
1
answer
92
views
Limit of Taylor coefficients
I want to calculate the following limit:
b[n_] := (D[1/(1 - t), {t, n}] /. {t -> 0})/Factorial[n]
Limit[b[n], n -> ∞]
(* Indeterminate *)
where ...
0
votes
1
answer
88
views
When running code to compute a sequence, loop variable gets set to a constant
I would like to write Mathematica code to read in a list of sequences, and print the sequence definition ($a_n$), along with the sequence evaluated at a few values of $n$.
...
5
votes
0
answers
61
views
How to use Shortest[___] with Sequence pattern matching?
Shortest[] doesn't appear to work with Sequence s. Is this a bug or a feature? What can I do to force the following ...
0
votes
1
answer
22
views
Confusing result when pattern matching a BlankSequence (__) to a list, then calling unary function on the list [duplicate]
The following makes sense to me:
In[1] = f[a, b] /. f[x__] -> x
Out[1] = Sequence[a, b]
In[2] = f[a, b] /. f[x__] -> {x}
Out[2] = {a, b}
However, the ...
0
votes
0
answers
21
views
Difference Equation with Upper Boundary Condition, Lower Terms Not correct
I am struggling to understand the solution Mathematica is providing for the following recurrence relation
As I have written a[i] I expected the following behavior
<...
10
votes
7
answers
649
views
Select data from a structured list
Let's suppose we have the following structure of data
...
1
vote
2
answers
101
views
we want to get all possible values with $a_1$
I would appreciate it if somebody could help me with the following problem:
Given
$$a_{n+1}=\begin{cases} \dfrac{a_n}{2}& (a_n \: \text{even})\\
n{a_n}& (a_n \: \text{odd})\end{cases},\:a_8= ...
0
votes
1
answer
78
views
Problem with For Loop when evaluating a recursive function at multiple points
I am running into problems with my For loop when trying to evaluate my expression. Fix some parameter values :
...
1
vote
3
answers
108
views
Rewrite the list without certain elements in the sequence
I have a list1:
...
4
votes
4
answers
208
views
One-to-multiple values relation from two excel columns
I have excel file with two columns:
After data import I have the following list:
...
2
votes
5
answers
273
views
Subsequences with distinct values
(this question was modified after initial answers)
For a sequence
x = {6,4,2,4,2,4,6}
y = Subsequences[x]
gives the list of ...
3
votes
2
answers
134
views
Determining the run length of elements in a list that satisfy a pattern
Is there a simple way to determine the run length of elements in a list that satisfy a pattern?
For example, consider the following list:
...
3
votes
2
answers
191
views
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:
...
5
votes
1
answer
82
views
Isolating sequences from a list based on a formula
SeedRandom[4];
alist = RandomInteger[{-4, 4}, 100]
From this list, I can isolate similar neighbors of length two:
...
5
votes
3
answers
231
views
Selective deletions from a list
i have two lists of strings with unequal numbers of subelements in each.
i would like to remove from lis2 all instances where a pattern in lis1 appears in lis2:
...
2
votes
2
answers
193
views
Trouble understanding function composition?
I made the following code:
Cs = {{0, 1}};
f[x_] := (Clear[s]; s = (x[[2]] - x[[1]])/3; Splice[{{x[[1]], x[[1]] + s}, {x[[1]] + 2 s, x[[2]]}}])
Observe that we can ...
0
votes
0
answers
48
views
How to find the sequence function $f(n,x)$ of the three given functions?
I have the three functions $f(2,x)$, $f(3,x)$ and $f(4,x)$ where $x>0$
...
2
votes
2
answers
265
views
While loop not working problem [closed]
I am new to Mathematica ,and I am trying to implement this while loop which adds all odd Fibonacci numbers less than or equal to 2 million but it keeps outputting 0 for sum.
Any solutions for that?
...
0
votes
0
answers
43
views
Problem with FindGeneratingFunction
I have a lengthy function of a real parameter $n$ that generates values $val$ for each $n$ {$n$, $val$}:
...
6
votes
2
answers
198
views
Longest common subset sequence with gaps
I would like to find the longest common subset (including a gap of x) within two lists.
Example:
A = AAABBBBCCCCC
B = CCCBBBAAABABA
We can use
...
1
vote
1
answer
122
views
RSolve unable to solve the equation
I gave the following code as input:
RSolve[x[n + 1] == 1/2 x[n] + 2 Log[x[n]], x[n], n]
Mathematica gave the same output:
...
0
votes
0
answers
60
views
Is there a concise way to generate a continuous less-than relationship?
Actually, I have a ton of variables, Let me simplify it to 4 in this post.
vars = {a, b, c, d};
0 < Less @@ vars < 10
0 < (a < b < c < d) < ...
0
votes
1
answer
84
views
How to solve this RecurrenceTable in Mathematica
I would appreciate if somebody could help me with the following problem:
Q: How to define this in Mathematica.
...
0
votes
1
answer
204
views
Variable dimension tables with variable ranges
I need to construct a table that has variable dimension and variable ranges (see for tables with variable dimensions and constant ranges, e.g., this question).
Suppose there is a list ...
3
votes
1
answer
90
views
A possible issue in combination of the Infix operator ~ with Sequence [closed]
There are other similar questions on this site about using the Infix operator for more than two arguments, which I have read. But there is one thing that I wasn't able to understand and couldn't ...
0
votes
0
answers
67
views
FindSequenceFunction with very small numbers
I need some help with FindSequenceFunction because at the moment it seems like a black box to me. For example, it deals with
...
5
votes
1
answer
102
views
Patterns are not Sequences are not Lists, or: Global Function Argument Reversal
H[z_] := z /. {F[p__] -> F[Reverse[p]]}
F[{x, y}] + F[{x, z}] + F[{}] // H
Almost. It gives an annoying "Nonatomic Reverse" error message at the ...
2
votes
1
answer
80
views
Defining function with arguments in a specific pattern similar to Graphics[]
I'm trying to define a function that is of this form:
...
2
votes
0
answers
105
views
Finding recurrence relation from an inexact numerical sequence
Consider the recurrence relationship
d[0] = 0;
d[i_] := (1 + Sqrt[1 + 4 d[i - 1]^2])/2 /; i >= 1
which generates the following sequence (generated by using <...
1
vote
0
answers
34
views
What subsequences does SequenceReplace consider
Consider SequenceReplace[{a, b, x, x, a, c}, {a, e_} :> e].
What subsequences does SequenceReplace consider?
The ...
0
votes
1
answer
66
views
Using :> vs -> in SequenceReplace
The first example on the page for SequenceReplace is the following:
SequenceReplace[{a, b, x, x, a, c}, {a, e_} :> e]
...
1
vote
1
answer
209
views
Extract function argument sequence
Is it somehow possible to access and reference the sequence of arguments of a non-pure function?
For example if I want to take the derivative with respect to the n'th argument, a pseudocode example ...
4
votes
1
answer
174
views
Find the longest sequence of "1" in a SubList
I'm trying to return the sublist(s) with the longest sequence of 1, although my code is working in a majority of cases, there are exceptions that I don't understand .
Example:
...
7
votes
4
answers
424
views
Find the longest sequence of "1" in a matrix row, and its position
I would like to find the longest sequence of "1" (consecutive ones) in rows of a matrix; moreover, I would like to know the position of this sequence in the matrix .
Example:
Input :
...
3
votes
1
answer
78
views
How to Map over a BlankSequence? [closed]
I would like to replace any function f[x, y, ...] in a certain expression with the same function with all its arguments squared, i.e. ...
4
votes
1
answer
82
views
SequenceSplit around empty sequences is inconsistent
Bug introduced in 11.3 and persisting through 12.3
Only the first one recognizes a zero-length sequence between non-X's.
...
4
votes
1
answer
69
views
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:
...
3
votes
2
answers
239
views
Calculating Average Price and P&L Efficiently Without Loops
A very common task is stock portfolio evaluation is to calculate the average price of stock holdings for a sequence of trades and from there to calculate the (realized) profit or loss. Obviously one ...