Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

learn more… | top users | synonyms (3)

3
votes
6answers
156 views

Change sublist based on position

Supposed that: list = {2, 3, 5, 7, 9}; sublist = {{3, 3, 5}, {2, 2, 2, 7, 9}}; I want to change each sublist in sublist as following: Find the positions of ...
5
votes
1answer
656 views

All possible topological orderings of a graph

TopologicalSort[] returns one of many unique orderings. From wikipedia: if a topological sort does not form a Hamiltonian path, the DAG will have two or ...
0
votes
2answers
178 views

Animate a sequence of bitmap-like data Mathematica 9.0.0

I am new to Mathematica, but already find it a very nice tool. Right now I am trying to create an animation of numeric data, where each frame corresponds to a distinct text file with a table-like ...
6
votes
7answers
325 views

Sum of two functions, list processing

I am creating some simple graphs of functions defined by ordered pairs. Students are learning about "operations on functions", in this case, adding functions. If I have two functions defined by ...
7
votes
5answers
234 views

Better way to make a certain list with palindromic sublists

Here is my code, which works, but seems a little too long, I think might be a more refined version. ...
4
votes
3answers
150 views

Appending to sublists using “anchor” values

Say I have a set of lists that look like this: ...
1
vote
3answers
126 views

Accessing sublists conditional on their length

Say I have a list that looks like this: ...
3
votes
0answers
67 views

Listing all combinations produced by picking one element from each of several sets [duplicate]

I have a problem like this, I am given the following sets {a,b,c}, {d,e,f}, {h,i,j}. I want to pick one element from each set, and output a list of all the ...
0
votes
2answers
100 views

How to extend “List-of-numbers-with-number” arithmetic to “List-of-X-with-X” arithmetic? [duplicate]

I'll start with a couple of examples (since this is all one can get from the documentation anyway). First, adding lists of numbers equal length is done term-by-term. E.g. ...
10
votes
4answers
282 views

Searching linked lists that contain lists?

Following the advice I've read here and other sites, I've been trying to use the Mathematica equivalent of a linked lists... ...
7
votes
6answers
200 views

How to join held Lists?

Let's say I have a = Hold@{2+2} b = Hold@{4+4} How can I get Hold@{2+2,4+4} ie join the two held lists ? More ...
1
vote
1answer
121 views

Assumptions about list elements

I am trying to simplify some expressions using assumptions and got an inconsistent behavior of Mathematica 9 when working with indexed variables. Consider ...
6
votes
6answers
274 views

Sort a list of coordinates by frequency from first component of each coordinate

The situation is that I have a List like this: ...
1
vote
2answers
232 views

How to pick a solution from a list of solutions using a test?

I have a list of solutions that depends on a parameter b3 and I'd like to get the solution for which the x value is minimal when ...
4
votes
4answers
200 views

How to construct tuples with a given order?

How do I create a list of tuples with an ordering imposed on them, where each element is from a generating set? Specifically, I'm trying to create a listing of tuples $(x_1, x_2, ..., x_n)$ such that ...
14
votes
6answers
706 views

How to find the distance of two lists?

I have two lists as the followings: ab = {1, -1, -1, -1, 1, 1}; ac = {1, -1, -1, 1, 1, 1}; How I can find the difference (more precisely, the edit distance) ...
12
votes
5answers
288 views

Can ReplacePart be sped up?

Test case: ...
10
votes
5answers
503 views

How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard ...
5
votes
1answer
212 views

Selecting a list from a list of lists

In working through Programming Paradigms Via Mathematica (A First Course) I have come across this two part question: A permutation of length "n" is a list of the first n positive integers in ...
11
votes
5answers
903 views

How can I simulate this animation of checking for prime numbers?

I can only implement a very simple one, I want to make my code look like that. Any better ideas? ...
2
votes
2answers
205 views

Deleting parts of groups that do not have equal dates

Find the intersection of dates within the pair and remove the other dates & corresponding prices. Also keep the list in same format as it currently is in. Let me explain: Each stock has closing ...
2
votes
3answers
360 views

Select sublists with second element nearest to zero

I've got some big lists from which i need some data (one of the big lists). To be specific, I need to divide this biglists in sublists of the same length (10000), and form a new list with the mean of ...
15
votes
3answers
584 views

How to partition a list to make each subset's size equal and mean as close as possible

Suppose we have 3 lists each with 18 numbers like this: ...
8
votes
10answers
345 views
1
vote
1answer
128 views

Extracting lists from list based on length

I have a list looking like this; ...
0
votes
1answer
116 views

Using sublists returned from a function as elements of a list argument to an other function

This is a contrived example, but it gets the point across. I am looking to use the following as inputs: ...
17
votes
12answers
1k views

Pick elements of largest absolute value

For example, given list = {{1, -3, -5}, {2, 1, 6}, {0, 2, 4}, {-9, 2, 6}} should return: {-5, 6, 4, -9} Updated I found ...
4
votes
0answers
165 views

Replacing and combining elements in a list [duplicate]

I am trying to increase the level of nesting in the following list while adding a 'tag' to each leaf: ...
1
vote
0answers
35 views

How to divide all rows of a matrix by their row sums [duplicate]

I've got a general matrix K that I would like to divide it's row's by the row sums of the matrix. I could get this going by doing ...
5
votes
2answers
472 views

How to combine elements of two matrices?

Given two matrices m1 and m2, e.g.: m1 = {{a1, b1}, {c1, d1}} m2 = {{a2, b2}, {c2, d2}} How can one obtain the following? ...
0
votes
2answers
133 views

List manipulation - End loop

Given are two matrices (a & b). I want to end the For-loop if all values in the matrix (a minus b) are smaller than 7, in contrast to any value in the matrix (a minus b) is smaller than 7. Can ...
2
votes
1answer
374 views

Extracting a range of data from a table

I have text file with data in 2 columns. I have imported it using the following line c = Import["ab", "Table"]; This text file has a large amount of data, and I ...
1
vote
1answer
199 views

Map a function conditional on elements at multiple relative positions in a list

I figure this question has many solutions, and if an answer already exists it would be nice just to be referred to it. I need a function that 'maps' over my list and produces a list of equal length ...
4
votes
2answers
233 views

Can someone explain this code for joining two lists by the first element of each sublist?

Background (which may be skipped, unless context is needed) I've recently begun learning Mathematica (and only up to chapter 3 of Wellin), but wanted to write some code to get a better feel for ...
1
vote
1answer
80 views

Create a new list under conditions from an existing one

I have an external file (data.out) which I read it with Mathematica using data = ReadList["data.out", Number, RecordLists -> True]; This file contains three ...
8
votes
3answers
198 views

Select and Blank

I try to filter sublists of a list which match a pattern. test = {{"String1", "a"}, {"String2", "b"}, {"String3", "a"}, {"String4", "a"}}; The result should ...
4
votes
4answers
164 views

Robust function for manipulation of nested lists

I have a nested list of the form: ...
2
votes
1answer
200 views

How to compute a discrete histogram of a list [duplicate]

I'm trying to compute the discrete histogram of a set of values. By histogram I mean the absolute frequency a value appears on the dataset, by discrete I mean the values are from a discrete set, e.g. ...
0
votes
1answer
122 views

Reuse a dynamic list [duplicate]

Consider this Dynamic list ...
1
vote
3answers
228 views

Creating overlapped block matrices

I'm doing an FEM assignment using Mathematica. (EK1 = {{a11, a12}, {a21, a22}}) // MatrixForm (EK2 = {{b22, b23}, {b32, b33}}) // MatrixForm I don't know how ...
7
votes
3answers
1k views

Simulate MATLAB's meshgrid function

Here is MATLAB's meshgrid. I came up with these implementations in Mathematica: ...
1
vote
2answers
273 views

How do I create matrices with arbitrary list restrictions?

I want to randomly generate a square matrix of dimension n with entries in the list StartingEntries, and also satisfying that for any such matrix M, the matrix Inverse[IdentityMatrix[n] - M] has ...
8
votes
3answers
187 views

Preserve information in flattening a nested list

I have a series of lists in the form below: list={ {1,1} , {2,2}, {3,{3,1},{3,2},{31,{31,1},{32,2}}} } Its a nested list which the dimension is changing case to ...
4
votes
4answers
256 views

Elegant Matrix Combinations

Suppose you have a matrix (mxn), simplified for illustration m= {{a, b, c}, {d, e, f}} And a set of combinations (simplified for illustration purposes but can ...
0
votes
2answers
148 views

Compute percentages in a list

I have a data file which contains thousands of lines and each line has eight elements. Here is a small sample of the data file ...
1
vote
1answer
194 views

ListPlot under conditions Part II

I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue: ...
4
votes
4answers
258 views

Generate Non-Singular Matrix of $n*n$ dimension

I want to create a function that will make an $n*n$ matrix which is non-singular that will always retrieve the same matrix (meaning that the matrix will not be random each time). I tried using the ...
12
votes
5answers
508 views

Filtering elements from a list that appear only once

I want to be able to select elements from a list that only appear once. I originally had this: Select[Table[Count[list, i], {i, list}], # == 1] But the issue is ...
2
votes
1answer
135 views

Match a sequence of integers

I would to match a pattern p1 = 0,0,1,0,0 to the elements in listA. The elements are a boolean sequence that may look like this ...
-1
votes
2answers
97 views

Manipulate store values

Is there a way to store the numerical values from a manipulate function in the form of a table? For example, if the function is f[x_] := x^2 - 2x Can one store ...