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

learn more… | top users | synonyms (3)

2
votes
3answers
116 views

How to do subtraction with sets in which the elements have multiplicity indicators? [duplicate]

I want to do subtraction with sets l1 and l2, which contain multiplicity indicators. For example, ...
6
votes
3answers
222 views

Loop function over list [duplicate]

I would like to divide element 1 of a list by element 2; element 2 by element 3, and so on. What is the best way of doing this? I have tried f = #1/#2 & ...
1
vote
1answer
157 views

How should I go about writing more functional and list based code? [duplicate]

I've heard that Mathematica is usually faster when the code is list-based and/or uses a functional paradigm. I'm still working on getting the hang of this; there are a lot of ...
2
votes
2answers
105 views

Deleting elements on a list by the first element of another list

I was trying to make this L1 = {{2, 1}, {6, 4}, {8, 7}, {9, 5}}; L2 = {{2, 9}, {9, 6}}; L = Union[L2 , L1] And I used this: ...
6
votes
3answers
266 views

Mapping a function that assigns values to a list over a different list

I'm trying to get used to Mathematica's approach to programming and list manipulation, and am struggling with one thing. Say that I have a function f which takes a ...
0
votes
2answers
79 views

Code for sum of exponential divisors function

Consider $n = p_{1}^{a_1}\cdots p_{r}^{a_{r}}$. An integer $d = p_{i}^{b_{i}} \cdots p_{r}^{b^{r}}$ is called an exponential divisor of $n$ if $b_{i}$ divides $a_{i}$ for every $1\leq i \leq r.$ I am ...
1
vote
1answer
101 views

How to apply compiled function on list

Compile function output error: How to apply compiled function on list? ...
2
votes
1answer
69 views

Convert Integer to Numeric with Replacement rules

I have a long list of triples, each looking something like {AGO, 1988, 2345.23}. Some of these, however, have an integer in the third spot, like this: ...
1
vote
0answers
112 views

Using Part within a Compiled Command

I'm looking to define a multi-line function that makes use of the "Part" command. A toy example: ...
1
vote
0answers
69 views

Produce {f[x],g[y],h[z]} in as many ways as possible [duplicate]

I have two lists of equal lengths but for my task I will use 3-element lists , namely {x,y,z} and {f,g,h}. The first contains ...
1
vote
2answers
104 views

Add a column to a matrix as a function of the other columns

I was wondering if its possible to add a column to a matrix by a formula that uses all other columns, like this: ...
0
votes
3answers
370 views

Find the number of nonzero elements

How do you find the number of elements in a matrix that are non-zero. For instance, the following matrix has 5 nonzero elements. ...
0
votes
1answer
183 views

Performing matrix multiplications with a list

I have a question in regards to PseudoInverse. I have $A$, an $n\times 2$ matrix, and when I want to compute $(A^T A)^{-1}A$, by using ...
6
votes
2answers
117 views

Get brief help for a set of functions

When we are in console mode or working with a notebook we can get brief help about a function just by shift-entering ?function I would like to have a list like ...
4
votes
2answers
1k views

How to combine two vectors into a matrix by columns?

I know it may sounds idiot, but I've been looking through the document, and couldn't find a way to combine two vectors say {a, b} and ...
3
votes
3answers
264 views

efficient way to give nearest neighbour and next nearest neighbour of every point in a point set

Suppose we have a point set, the points are labeled 1,2,3,....n. And p[i] is the coordinate of the point. Now I want the label of nearest and next nearest point ...
0
votes
0answers
43 views

Store results of inequality [duplicate]

I eveluated some values using Reduce commend and I store them in a Table ...
8
votes
7answers
646 views

How to partition a list in a specific way

I have a list: a = {{1, 2, 3, 4, 1, 2, 3, 4}, {5, 6, 7, 8, 5, 6, 7, 8}}; Using Partition and ...
17
votes
9answers
911 views

How to replace an element in a list based on the value of the next element?

I use Mathematica a little bit. I try to understand it, but it is hard I have a list of 5 numbers selected randomly from 0 and -1. I have to replace a 0 with a 1 when the 0 is followed by -1. My ...
4
votes
1answer
142 views

Efficient ways to rotate a ListPlot?

I have a numerical solution from a differential equation that is in the form of a list, in $(x,z)$-plane. I would like to rotate the 2D ListPlot around the $z$-axis ...
11
votes
10answers
509 views

How to pick increasing numbers from the list

How to pick increasing numbers from the list. lst = {5, 3, 6, 2, 7, 4, 8}; out: {5,6,7,8} So many interesting ...
5
votes
6answers
272 views

Convert array from {{…}} to “[[…]]”

I have made this function: conv01 = Map["["<>StringJoin@@Riffle[#,","]<>"]"&,Map[ToString,#,{2}],{0,1}]& to convert: ...
0
votes
1answer
107 views

How to create 2k sized vector in k sized loop

I want to solve a system of simple differential equations. At some point I need to solve non-linear system of algebraic equations with Newton method. I would like to efficiently create a right hand ...
6
votes
2answers
176 views

how recover lost data of coordinates from contourplot of mention data?

I have made Contour Plot for a lot of data, like this ...
1
vote
2answers
105 views

How to return matching sublists or empty list

How to return matching sublists or empty list m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}}; m2 = {{1, 0.5}, {0, 0.4}, {0, 0.1}}; Commonest[Join[m1, m2]] out: ...
2
votes
2answers
162 views

Organise data in table

I have a large amount of data available (in excel), which is not very organised. I can do this by copy paste, but I am trying to do this using mathematica. Hopefully someone can help me. I imported ...
-2
votes
1answer
76 views

Using Product for different variables

when using product in mathematica the initial and maximum value of the product will be the variable itself that will be maupulated. what I need is to make these initial and maximum of the product as ...
3
votes
2answers
201 views

How can I scale the y axis?

I have a file I import and read into a table of $2 \times n$. I can plot this data using the following code: ...
1
vote
3answers
210 views

Code hanging inside a For loop

I'm pretty new to Mathematica (and functional programming in general). I'm working on some code to find winners (maximal values) in a list. The code I have that is hanging is this line. ...
4
votes
2answers
127 views

Coordinates for multiple countries

I am trying to plot polygons for multiple countries, say "UnitedStates" and "Canada". US data is generated thus: ...
8
votes
8answers
340 views

How to use Map inside MapThread?

Given this input lst1 = {{a, b, c}, {d, e, f}}; lst2 = {1, 2}; and the goal is to generate this output ...
15
votes
2answers
1k views

Is there an equivalent to MATLAB's linspace? [duplicate]

Does Mathematica have an equivalent to Matlab's linspace? I want to make a list with "start", "stop" and "number of points". What is the neatest way of doing this?
3
votes
6answers
256 views

Compute ratios of elements in two lists

I have two lists, say a and b, both of length n. I'd like to compute the following: ...
2
votes
2answers
71 views

How can I generate a variable-length list of options in PieChart?

I would like to allow a user to manipulate the segments of a pie-chart, which is to be generated from a list of a specific format. The code looks something like the following: ...
11
votes
4answers
506 views

List comprehension in Mathematica

Python supports a concept called "list comprehensions". Following is sample example ...
13
votes
11answers
752 views

How to get list of duplicates when using DeleteDuplicates?

This might be easy, but can't find a way to use DeleteDuplicates to get also list of the actual duplicates. Example: ...
0
votes
0answers
63 views

How to delete duplicated sublist [duplicate]

I have a list like this: ...
-1
votes
2answers
212 views

How can I extract when a select condition is met in a do loop the value of the iterator?

I use the following code to find out the number of consecutive prime numbers using a formula $n^2+n+i$ found out by Euler (starting from n=0): ...
5
votes
6answers
179 views

Reversing every second “row” in a list

I have a list that is obtained by flattening a matrix list=Flatten[Table[{i, j}, {i, 1, 4}, {j, 2, 6, 2}], 1] {{1, 2}, {1, 4}, {1, 6}, {2, 2}, {2, 4}, {2, 6}, ...
12
votes
4answers
330 views

How to enumerate all possible binary associations?

Suppose I have a list of symbols like: {a,b,c,d} I would like to enumerate all possible binary associations (combining symbols and/or sublists pairwise): ...
0
votes
3answers
93 views

List of squareful, cubeful, etc. numbers

The following works: ...
4
votes
2answers
116 views

How to constrain the generation of all possible orderings?

Here is code from Simon Woods' answer for getting all possible weak (equal ranks allowed) orderings for $N=3$ objects: ...
1
vote
2answers
156 views
11
votes
7answers
378 views

Concatenation of lists in a Fibonacci-like pattern

I am trying to create a List of elements that follow the general pattern: $$X_{n+1} = X_n X_{n-1}$$ where the operation on the right hand side is concatenation, i.e., joining. I want to achieve the ...
0
votes
3answers
87 views

How to get the indices of values in a list which are NOT an specific integer?

I got a real array A, where Dimensions[A] == {5000, 5000, 5}. Some of the values in A are ...
4
votes
2answers
167 views

How to insert / merge a list into another list?

Background: I am working on a 2D geometry algorithm where I need to insert a list of 2D points into another list of 2D points. Somewhat to my surprise I found no Mathematica function capable of doing ...
11
votes
3answers
294 views

How can I remove the singleton dimensions of an array? [duplicate]

If I have an array A, for which Dimensions[A] is {9, 9, 1, 1, 3, 4}, how can I convert ...
3
votes
2answers
262 views

Filtering and Replacing outliers

I have a set of data that measurements of temperature vs time (date). It is easy to realize when the sensor went wrong as one might see a blip on the data. How to teach to Mathematica to: 1) Detect ...
2
votes
2answers
116 views

Interpolating a list with exclusion [closed]

I have a list, data, where the elements data[[i]] range over i from ...
1
vote
5answers
167 views

How do I find the maximum value from the given set of data?

I have a set of data like {{x1, y1},{x2, y2}, ...,{xn, yn}}. From this data can I find the value of x for which ...