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

learn more… | top users | synonyms (3)

-1
votes
1answer
132 views

How to change the value of an array that is outside the For loop, from inside the For loop [closed]

H is a square matrix which depends on the vector d which I define below. I redefine d in each iteration but I need to plug it in H in each iteration aswell. It is easy if I define H inside the For ...
10
votes
4answers
323 views

How to add lists with unequal length?

Given lists of unequal lengths, I want to add them together element-wise, treating missing elements as zero. For example, {1, 2, 3} + {a, b} + {x} should give ...
3
votes
2answers
132 views

Creating a list from other lists and varying the number of elements that get added

Suppose I have listA = {M, F} and ListB = {a,b,c} I want to make a new ...
0
votes
1answer
117 views

Using a loop to make a new list by taking elements from multiple lists [closed]

I have defined three lists and I need to be able to take elements from them periodically and put them in a new list. I know I need to use some form of a loop but I am at a loss. Any suggestions?
0
votes
1answer
95 views

How to extract data from a list? [duplicate]

I have a long list of coordinates defined in some 8D space. I need to extract the first three coordinates only. How ? For example : ...
4
votes
2answers
335 views

List reversion inspired by Python

In python, if you wish to reverse a list, here is the trick: range(10)[::-1] => [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Note: ...
3
votes
1answer
176 views

How to store values indexed by integer partitions for fast access?

I have a huge list of values indexed by integer partitions. If I store them simply in a list, then, when I want to access the value corresponding to some particular integer partition, I have to find ...
-7
votes
5answers
385 views

Translating MATLAB's cell2mat into Mathematica

How I can define a function in Mathematica such that it acts same as the cell2mat command in MATLAB? Example (in MATLAB): ...
1
vote
2answers
337 views

How do I divide the columns of a matrix by the sum of its elements?

I am trying to create a transition matrix for a network. In order to do this, I need to sum down the column (the out degree), and then divide the column by the out degree in order to normalize it. ...
0
votes
1answer
115 views

Dynamic List Building and Exporting [closed]

My ultimate goal is to have a text file that contains the following information in the following format exported to a text file: ...
0
votes
2answers
118 views

ListPlot of lists with specified x coordinate

I want to do: ListPlot[{{x1, y1}, {x2, y2}, ...}] each y being not a number but a list of numbers. I tried: ...
4
votes
2answers
235 views

Sorting a matrix alphanumerically

Somewhat related to Sort matrix by columns and rows without changing them, but more general. I'd like to sort a square matrix (a 3 by 3 in my case, but surely the general solution will treat any), ...
3
votes
3answers
193 views

How can I name “a[[i]]” the parts of Table “a”? Or how to make Table “a” grow inside FindMinimum?

Let's say I want to minimize a function that uses a Table named a with the Conjugate Gradient Method of ...
3
votes
2answers
425 views

Adding and subtracting from elements in a list

I'm trying to solve an aparently simple problem. Given a list of length n, {a1,b1,c1,d1...} I want to perform two simple ...
8
votes
4answers
136 views

Mark selected sub-lists in the list they were selected from

I've got this simple problem with two lists. I select some items from a list, but I want to visualize the difference between the previous list and the list that I create with ...
9
votes
5answers
623 views

Building a continued fraction

I've completed a problem that involves approximating $e$ by a continued fraction: $$\frac{N_1}{D_1+\frac{N_2}{D_2+\frac{N_3}{\ddots+\frac{N_k}{D_k}}}}$$ with the $N_i$ being the list ...
2
votes
2answers
237 views

Preparing data for making an ErrorListPlot

I often have the following notebook in Mathematica, which I use to make a dataset and associated errors: ...
1
vote
3answers
285 views

Convert coefficients of polynomials into a matrix

I have several sets of 5 polynomials of the form: ...
1
vote
1answer
68 views

How can I use list processing functions on data in a file?

How might I work with the following functions on a list, if the list is a disk based file? Partition[] DeleteDuplicates[] Split[] SortBy[] The file is too ...
3
votes
2answers
89 views

How to generate a list from an iterator and some arbitrary function

Suppose I'd like to generate a table of integers: Table[i, {i, 10}] Great; now suppose I want only the integers that are even ...
3
votes
2answers
239 views

Colors associated to parts of a 3D distribution of points

Suppose we have a long list of random points (cartesian coordinates) in 3D space. coords := ...; Until now, I was associating colors in a radial way, from the ...
6
votes
4answers
436 views

How to apply a function to a list of tuples

trialList = {{0, 24.701}, {1, 24.69}, {2, 24.733}}; f[x_] := x + 1; I would like to apply the function f to only the second ...
2
votes
1answer
108 views

How to extract the bin width from a Histogram made with an automatic binning method?

I am using the Scott binning method with Histogram and Histogram3D to plot some data. How could I find out the bin width chosen ...
9
votes
4answers
243 views

How to pass a list of arguments into HoldAll

I have a list of arguments (which in reality is lengthy): arguments = {a, b, c} arguments2 = {a_, b_, c_} f[Sequence@@arguments2] := a + b + c Note: It seems ...
11
votes
5answers
308 views

Faster way to convert triangle list to edge list with no duplicates

I have a list of triangles returned by a Delaunay triangulator, in the following format: ...
6
votes
2answers
310 views

How to punch a hole in some 3D distribution of points

Suppose we have a long list of 3D Cartesian coordinates, defining a distribution of random points in 3D space. How could we remove all the points inside a sphere of radius ...
6
votes
1answer
129 views

Position with Except returns first item {0} and last item {}. Why?

Here is a simple list: l={1, 0, 2, 1, 0, 1, 0, 1, 2, 0, 2, 0, 1, 0, 1, 0, 0} To get the position of non-zero elements I use ...
7
votes
1answer
237 views

DeleteDuplicates[] does not work as expected on floating point values

Here is my simple example, and in this case function DeleteDuplicates does not work as expected. I want to FindRoot of my ...
5
votes
3answers
300 views

Replace very small numbers by zero in the output of a list

I have a long nested list, but many elements are numbers of order 10^-18 or less, eg ...
4
votes
1answer
135 views

Integrating a list of functions

For the purpose of this minimal example, let's say we have a list of functions, like this: f[y_?NumericQ] := {NIntegrate[z*y, {z, 0, 1}], a y} I want to ...
1
vote
1answer
151 views

Syntax for integrating over limits specified by a Table

I wish to use NIntegrate to compute multidimensional integrals. However, I don't want to manually input the limits for the dimensions. I want to store the ...
4
votes
2answers
147 views

How to only work on sublists with non-zero (or positive) values

i have a large compositional dataset which contains non-zero and zero values. here is a sample: ...
3
votes
7answers
251 views

Remove elements at certain positions from all sub-lists?

Consider a big list where all the inner lists length's are the same list = {{x1, y1, z1, t1}, {x2, y2, z2, t2}, {x3, y3, z3, t3}, ...}; elementNo = {4, 3, 2}; ...
6
votes
2answers
361 views

Select elements of list within a date range

I have a list which consists of elements each of which has a date in DateList format, a number and a flag (Y/N). e.g. ...
13
votes
10answers
831 views

Pretty way to group elements at odd and even positions

How to make a function that splits list elements by odd and even positions? Shortest implementation wins. I myself came up with: ...
1
vote
1answer
57 views

PrependTo fails on a Table of Evaluated funtions

My task is something like this: PrependTo[Evaluate[Table[{x, Sin[x]}, {x, 0.1, 2 \[Pi], 0.1}], {0., 1.}]] where I tried also skipping the ...
13
votes
1answer
168 views

Ordering function with recognition of duplicates

Fairly often I have a need to get the Ordering of an expression but with recognition of duplicates. For example: ...
24
votes
4answers
1k views

How to efficiently find positions of duplicates?

Is there an efficient way to find the positions of the duplicates in a list? I would like the positions grouped according to duplicated elements. For instance, given ...
3
votes
2answers
307 views

For loop with steps other than 1

I would like to do a For loop with a jump 2*Pi instead of 1. For[j = 0, j <= nmax, (incr = 2 Pi), ...] Actually what I want to do is ...
11
votes
3answers
849 views

What is Mathematica's equivalent to MATLAB's filter function?

The MATLAB code filter(0.5,[1, -0.5], [1:10]) is equivalent to Rest@FoldList[(#1 + #2)/2. &, 0, Range[10]] I don't ...
2
votes
1answer
71 views

Replace a specified portion of an array with elements from another smaller array

This may be a trivial question, but I have been at it for a couple of hours and I have not made much progress. I have a 10 x 10 array (T) that I have used to generate an 8 x 8 array (Q). I want to ...
1
vote
1answer
172 views

Extracting information from list

I have a huge list that looks like this: ...
12
votes
9answers
419 views

Dropping n consecutive terms from a list periodically

Suppose I have the following list lis = Range[100]; and I want to remove n consecutive terms periodically from the list. For example suppose I want to drop terms ...
7
votes
4answers
456 views

How make f[{x,y}] evaluate as f[x,y]?

I frequently encounter the situation where I have a function of two real variables defined, e.g.: f[x_, y_] := 9 - x^2 - y^2 But then I need to feed into ...
3
votes
4answers
475 views

Extract function arguments

Is there a way to extract the arguments of a function? Consider the following example: I have this sum ...
0
votes
3answers
150 views

How to construct pairs in a list?

I have an expression like this, input = x[1] x[2]^3 x[5]^2; Fist step, we can get a list from the input expression, ...
1
vote
2answers
239 views

Select rows from table by keys

I am looking for a way to iteratively select all sublists with the same ID (my 1st column, residual columns are AbsoluteTime entries). First, I obtained the list of ...
0
votes
0answers
37 views

Correspondence between eigenvectors and eigenvalues [duplicate]

Let us say I have a matrix h (2x2). Now, I want to get the eigenvectors and eigenvalues of my matrix h: ...
4
votes
3answers
380 views

Separating positive and negative numbers into two arrays

$c$ is a vector with real numbers.I want to separate the positive ones and the negative ones into two vectors: $a$ and $b$. I have the following problem: When I do: ...
1
vote
2answers
762 views

Finding a best fit curve and plotting it [closed]

I have a list as shown below: m01 = {{250, 0.083121}, {200, 0.0888446}, {150, 0.0992422}, {100, 0.121567}, {50, 0.186825}} I'm new to Mathematica, and would like ...