All Questions

Filter by
Sorted by
Tagged with
10
votes
7answers
937 views

How to take the beginning and end parts of a list with simpler syntax?

So basically you have a table of some values, let's call it a: a=Table[n,{n,10}]; (*{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}*) And you ...
0
votes
1answer
66 views

How to make split tables in Join?

I have a command Table0[mS_]:=Table[{mS*i,i^2},{i,1,20}] Table1=Join[Table0[1],Table0[2],Table0[3]] When calling Table1[[1]] I expect to get the element Table0[1]...
0
votes
0answers
53 views

magic square with prime numbers of any order

how could you create a script in Mathematica that generates magic squares of order n, but that the numbers that form the square are all primes I've looked at what's in other answers but I can not ...
-1
votes
1answer
57 views

Operations between sets of integers [closed]

sorry it was impossible to put the code in Latex, he said that there were problems of indentation, I put the image
1
vote
0answers
72 views

Run function as loop over two matrices

I'm still wrapping my head around Mathematica syntax. I have a matrix clustersAll that looks like ...
3
votes
3answers
141 views

Using Through on functions that take multiple arguments

I want simple syntax that results in this: {{f[1, 2], g[1, 2]}, {f[3, 4], g[3, 4]}} though I'm willing to settle for: ...
0
votes
1answer
69 views

Scan and lists of lists

I am trying the following construction but I get an error message. Let l be a list consisting of pairs of integers. Let further ...
1
vote
0answers
117 views

Proper syntax for DeleteCases with conditions

List is an array of dimensions {61777, 3}. dist1 & dist2 are RegionDistanceFunctions. Using: ...
1
vote
2answers
158 views

How to manipulate a function (Append/Prepend) multiple times?

I'm having trouble trying to manipulate a function in a type of "loop" format. Essentially what I want to do is be able to manipulate the amount of Append functions ...
9
votes
1answer
348 views

Part not behaving the way I expect it to

p = {{1, 0, 0}, {0, 1, 0}, {0, 1, 0}}; p[[All, 3]][[1 ;; 2]] = {1, 1}; p I want to replace the first two elements of the third column of a 3x3 identity matrix. ...
0
votes
1answer
79 views

Generating problem text automatically

I want to randomly generate groups of radom parabolas to be graphed as follows: Graphing — Parabolas $\qquad f(x) = a\, x ^ 2$ (3 of them) $\qquad f(x) = a\, x ^ 2 + b\, x$ (3 of them) $\qquad f(x) =...
0
votes
1answer
88 views

How can I make ListPlot use my iteration as the x coord?

I have some code that takes a list of energies, plugs them into a set of recursion relations and numerically solves for each energy (15 energies total) and for each n(modes, 21 total) ...
7
votes
1answer
195 views

A question on the function Drop

I use the function Drop quite often. When looking at this question, my attention was caught by a use of Drop in a way I did not ...
1
vote
2answers
3k views

Tag List is Protected Error in simple script

I want to have a simple script that gives me all numbers $k \in \mathbb{N}$ in some range such that product of all their divisors is equal to $k^3$. Here is the code that I wrote: ...
1
vote
1answer
657 views

How to extract the first and last element

It is a elemental question maybe,but I am confusing still.If I have a 1-dimension list list a = Range[5] (* {1, 2, 3, 4, 5} *) ...
5
votes
3answers
146 views

Unexpected behavior of MapAt

For the description, I have a simplified problem like the following: MapAt[f[1, #1], {a, b, c, d}, #2] & @@@ {{1, 2}, {3, 4}} will give ...
1
vote
2answers
107 views

Use Accumulate while creating Table

Can I somehow create a list and its cumulative sum at the same time, e.g. with Table: Now I do it in two steps ...
3
votes
1answer
462 views

List positions without brackets [duplicate]

Suppose I have a list l which contains the indices of some array a. For instance, l = {{1,1},{1,2}} a = {{a11,a12},{a21,a22}} I want to access the elements of a ...
1
vote
0answers
64 views

Simple list manipulation [closed]

I have two lists: {1,2,3} and {a,b,c} and I want this result: {{1,a},{2,b},{3,c}}. What is the right command? How does one call such an operation?
5
votes
2answers
262 views

Why SetDelayed won't work

I'm trying to do this: Riffle[list = {a, b, c, d, e, f}, tem = RandomInteger[1, Length@list-1]] {a, 0, b, 0, c, 1, d, 0, e, 0, f} But I think this method is ...
3
votes
2answers
151 views

Sorting and keeping the main format of list numbers [duplicate]

I have a list with these elements: list={1/2 (1 + Sqrt[5]), 1, 1, 1/2 (1 - Sqrt[5]), 0}; I want to sort them with ...
0
votes
1answer
336 views

Summation over list elements

As we know, one of the simplest way to do a summation (with special intervals) over list elements is using Sum[list[[i]], {i, 3, 8, 2 }] (*with steps of 2*) for ...
13
votes
1answer
1k views

When to use @@@ vs. /@ [duplicate]

So much thanks to Szabolcs in improving sequence.. for complete explanation. I am so glad to read all explanation which fundamentally remove the problem. But in number 4 of its explanation pointed to <...
5
votes
3answers
288 views

How to imitate list comprehensions for constant arrays?

In Python, ['a'] * 10 generates ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] and ...
2
votes
1answer
143 views

how to manipulate indices in a table/vector

Perhaps I'm missing something very basic. Could somebody guide me how to manipulate indices of a list. For example, if I have ...
1
vote
1answer
206 views

Cannot use Part in Pure Function [duplicate]

I need to select some lists in the nested list of form of {{1,2,3},{2,3,4}}. I have used Select to complete my work. But when I tried Position, it doesn't work. For example, ...
0
votes
2answers
82 views

For Loop in Mathematica {n, factored form of x^(n)-1} for 95<=n<=105

I am new to mathematica. I am trying to write a for loop to print out {n, factored form of x^(n)-1} for 95<=n<=105. I have followed the directions of another for loop, and gotten the following ...
0
votes
1answer
59 views

Help for properly writing simple derivative expression

I need help to write the following expression (only 1 iteration): f(x) = ...some basic function... f[X0,...,Xp] = f(p)(x0) / p! What I have so far: ...
1
vote
1answer
101 views

Appending functions to a list [duplicate]

Could someone please explain the difference between these methods, and possibly a nicer way to get the first result? (This is a toy example and in my real program I'd like to use ...
1
vote
1answer
68 views

How to set the values into some variables from different lists [duplicate]

I have a list of Values and a list of variables. I want to set the Values into Variables. Assume the following code: ...
1
vote
1answer
952 views

Compile with array operations

When I use the function f with only the Module ...
1
vote
2answers
174 views

MapThread with List Manupulation

I have the following three lists: ...
3
votes
1answer
161 views

MapThread over a nested list

This may be a simple question. Please close it if it is already answered. I have a nested list kr = {{35, 32, 27, 20}, {36, 33, 28, 21}, {37, 34, 29, 22}} I ...
3
votes
1answer
248 views

Levels and slots

I am struggling with levels and #, if I understand this I think I will be able to grasp the entire concept. ...
6
votes
2answers
559 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 ...
-5
votes
1answer
1k views

Split dataset based on the first column [duplicate]

I have a dataset which I want to split based on the first column. The data looks like this ...
2
votes
2answers
207 views

Extracting counts of contiguous zeros and ones from a binary array

I'm a novice with Mathematica, but you guys have been very helpful to me in the past. I have a binary array [100, J repetitions] consisting of zeroes and ones. I'd like to extract a histogram of the ...
1
vote
1answer
323 views

Bincounting a list

I'm a Mathematica novice here. I'm trying to execute the following code to add random 1's into a zero matrix, repeat this many times, and then bin/histogram the number of nearest neighbor 1s. Can ...
3
votes
1answer
149 views

Filtering the elements of an array to split them into two categories

So, I am new to Mathematica, and I am trying to write something that involves taking values from one array and separating them into two different arrays. My code for doing this is: ...
5
votes
2answers
492 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
592 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 ...
26
votes
1answer
1k views

Using Transpose with a list as the second argument

I'm having difficulty understanding the Transpose function. I know what the transpose of a matrix is, not a problem, and I see that applying the ...
11
votes
3answers
216 views

Why can't I use Sequence to perform a Select like task? [duplicate]

Suppose I wanted to write down a list of $p^2$, for $p$ a prime between $1$ and $20$. I would expect Table[If[PrimeQ[k], k^2, Sequence[]], {k, 1, 20}] to work. ...
7
votes
2answers
784 views

Extracting parts of nested lists of rules using a syntax similar to JsonPath or Xpath

Given an example data set: ...
2
votes
1answer
2k views

Indices and variable definitions in Mathematica

Does anyone know how I can do this in Mathematica? Just an example.. Defining indices and variables (defined over indices), "mapping" variables and indices: ...
4
votes
2answers
321 views

Finding the position of a specific value in a list

Is it possible to easily find the position of a specific value in a list? For example, if the list is {{x1,y1},{x2,y2},...,{xn,yn}} I would like to know the ...
4
votes
1answer
372 views

Path queries for tree-structured data

Can anyone suggest documentation or tutorials for developing path queries and indices for (XML-like) tree-structured data? Suppose data is organized hierarchically in key->value pairs, eg: ...
23
votes
7answers
2k views

Equating matrices (or higher order tensors) element-wise

Say I have two matrices (or, as in my case, higher order tensors) $A,B$, and I want to solve the equation $A=B$. To do so , I need a list of equations that equate entry-wise the elements of $A$ and $B$...
14
votes
2answers
3k views

Flatten at a certain level

In an earlier question the brainteasing fourth syntax variant of Flatten was discussed. I see that with ...
96
votes
4answers
5k views

Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...