Questions tagged [list-manipulation]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
25 views

List not same shape when using NDSolveValue [closed]

I'm trying to define a function from NDSolveValue, but it is returning the following error (imagem below). Here is the code: ...
1
vote
0answers
26 views

Question about a restricted rewrite rule [closed]

I just started learning Mathematica and I'm not sure why a function I defined doesn't work. So I'm trying to write a function that takes a list of vectors and eliminates all zero vectors (with respect ...
1
vote
1answer
69 views

restructure a list with brackets

I work with the following list data = {{a}, {{a, b}, {a, b}}, {{{a, b, c}}}}; In real, the dataset is much longer and each row has a different structure of having {...
2
votes
0answers
34 views

Replace part of list by applying operation to it [closed]

I want to replace, say, list[[i]] by f@list[[i]]. I can use ReplacePart as below, but I ...
4
votes
2answers
500 views

How to generate all possible functions combinations

Assume that I have 3 functions like this (total 10 functions in reality). f1[x_] := 3 x; f2[x_] := x^2 - 1; f3[x_] := 2 x + 5; Now I want to generate all possible ...
2
votes
1answer
86 views

Why does this DeleteCases not work? [duplicate]

I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me. ...
5
votes
2answers
194 views

List manipulation: all possible sublists

Say I have the following list {a,{b,c},{d,f,g},e} what is the fastest way to get the result lists ...
1
vote
1answer
54 views

Palindrome by deleting a character

I need to find a list of strings with input string length n for whom are palindrome by deleting a character from it . The strings are stored inside function ...
1
vote
0answers
43 views

How to compare and subtract elements in nested list to generate a new list [closed]

I have list of lists like this one: list={{1, 9, 4, 7, 2}, {1, 4, 7, 1, 8}, {0, 5, 7, 2, 9}} where every nested list have 5 elements. I want to compare the third, ...
2
votes
1answer
55 views

Find all substrings from a string by deleting characters from it

Problem Description : I need to create all substrings from a string by deleting letters from it without re-arranging the rest of the letters. For example, "us" is a substring of "...
0
votes
0answers
42 views

Split a String by minus and zero

How can a String like 0.0002230.0012730.000296-0.0014380.0011270.0014690.001457-0.001017` be converted to ...
0
votes
0answers
33 views

Export data to file

I have a function f[x,y,z,i] that returns the solutions {x1,y1,z1} for each step "i". I would like to use a repeating command (such as Do[...]) to get the outputs of this function f saved ...
1
vote
1answer
27 views

Insert string elements to an array

(Minimal example) I'm dealing with the following array : ...
0
votes
0answers
32 views

Converting a given region to a unit square with double integral

I have to write 4 equations.I am listing their code below.I am asked to convert the region obtained from these 4 equations to unit square.I have developed a code but I am getting an error. Can you ...
5
votes
2answers
83 views

Sort list by a condition on parameters

Consider the following list list={{{0,0,0},0},{{0,0,1},a},{{0,0,-1},-a},{{1,0,1},b},{{1,0,0},-b},{{1,1,1},a+b},{{1,1,1},a-b},{{-1,0,-1},{-a-b}},{{-1,0,-1},{-a+b}}}; ...
0
votes
0answers
33 views

Plot trajectories of 1D coalescing particles: Reshape irregular size array

My question boils down to: How can I reshape a list composed of sublists of different sizes? I am trying to plot the trajectories of 5 particles (1D), and if they collide, they merge into one same ...
2
votes
1answer
117 views

How can I list the common elements of two lists?

The elements of both lists are given as A={9,5,9,3}, B={9,9,5,5} In this case, how can I list the list {9,5,9} of the common elements of the two lists? (The order does not matter.)
1
vote
1answer
56 views

Evaluating list inside list in a table [closed]

I'm stuck with a List and Table command. I want to evaluate $F[x,y]$ and get all the possible configurations, knowing that x and y are lists. How I should evaluate this correctly in Mathematica? and ...
0
votes
1answer
48 views

listing according to constrain

Given a 3x3 matrix, check each of the columns starting from the first one, and if a column contains 1 or -1 the output is x, otherwise the output is y. Then list the sequence of these x,y as a vector. ...
3
votes
2answers
167 views

Recursion in String Length of Roman Numeral

I am new to Wolfram language (Mathematica) programming, I have below problems. To summarise the problem : The input is a positive integer, and the output is a recursive list of the lengths of the ...
9
votes
5answers
465 views

How to construct a tree from a preorder traversal

The list t1 = {1, 2, 3, 3, 4, 4, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2}; might be derived from a pre-order traversal of ...
1
vote
1answer
35 views

How to evaluate a function on all solutions given in output of a Reduce function

Say I have a Mathematica programme/function $f[z_,w_{} ] = \mathrm{Reduce}[\cdots]$ which outputs a list of solutions, which looks something like $$a = 1 \&\& ((0\leq b \leq 1000 \&\& ...
0
votes
1answer
69 views
4
votes
3answers
123 views

Select lists from a nested list such that each list contains a specific pattern appeared within certain position offset?

Say a nested list datatest and a sublist searchterm, I would like to pick up the lists in the ...
3
votes
1answer
69 views

How to extract certain plot points from a plot with a grid?

I have created a plot using the code below ...
2
votes
1answer
147 views

Create a matrix without definition of dimensions

is it possible to define a matrix without giving its dimensions in Mathematica, e.g. First line: mattest[[1,2]] = 1; Second line: ...
2
votes
1answer
73 views

How to get the complete list of subsets the pairwise intersections of which are empty

Given the list Range[6]. I want to get the sublists of length 2 where each element has length 2 and the pairwise intersections are empty. So I am looking for: ...
0
votes
0answers
63 views

How to use my code to calculate the following?

(Don't consider the context of this problem. Help with what you know and focus on the coding.) Consider the following: If $S=\left\{\frac{m}{2n+1}:m,n\in\mathbb{Z}\right\}$, $g:[0,1]\to[0,1]$, and $\...
4
votes
2answers
124 views
3
votes
2answers
59 views

Applying transformation rule for corresponding indices?

I have two lists, that looks like below list1 = {a, x, b, x, x, c}; list2 = {2, 3, 4, 5, 6, 7}; Any time there is an x in the ...
2
votes
2answers
104 views

Solving linear equations of two variables, where one variable is a list of numbers [closed]

For example: X + Y == 1 where X = {1, 2, 3, 4, 5} How can I solve for Y in Mathematica? ...
2
votes
1answer
41 views

Why are the inputs not being applied to the function in this MWE?

Consider the following MWE ...
5
votes
2answers
190 views

Dropping elements from a list

...
2
votes
0answers
32 views

Example of when explicitly using MapThread is better than giving a function the Listable Attribute

This answer says that Listable just makes the function automatically apply MapThread to its arguments. Does anyone have a simple ...
1
vote
2answers
89 views

What is the best way to rearrange the following list? [duplicate]

I have the following list \[ScriptL]0 = 4 mtablep = Riffle[Range[0, -\[ScriptL]0, -1], Range[\[ScriptL]0]] which produces the following: ...
2
votes
1answer
49 views

Definition of multiple variables from a list

I have a list of the form {{0, 0, 0, 0, 0, 0, a, b, c, d, e, f}, {0, 0, 0, 0, 0, 1, a, c, b, d, f, e}, {2, 2, 2, 2, 1, 2, b, f, c, a, d, e}, ... } and I would ...
4
votes
4answers
412 views

How can I rearrange my list?

I have this list, {{a}, {i1, i2, i3}, {1, 2, 3}} which I want to rearrange to this: {{1, i1, a}, {2, i2, a}, {3, i3, a}} ...
5
votes
1answer
67 views

Read binary files and separate the 64-bit unsigned integers into certain forms?

I have a binary file where each data is a 64-bit unsigned integer (little endian). For simplicity, let's say the data in testdata.bin file opened in HxD is: namely:...
1
vote
1answer
37 views

Cleaner way to fill in gaps in a list

(This is my first time posting code so I may have done it wrong.) I have a list of data that was collected and reported in 5 year increments for a couple of decades; then the gap was three years until ...
5
votes
2answers
92 views

Decomposing a list into certain structured nested list?

Consider the below list testlist = {0, 1, 2, 0, 0, 1, "a", "b", "c", "d", "e", "f"} I am trying to ...
0
votes
1answer
40 views

Use of Rotate left to shift a band structure

I have to apply a shift to a periodic band structure. A simple example would be ...
4
votes
2answers
59 views

Permuting elements in a nested list according to another nested list?

I have two lists (value and label). With the function Permute, I can permute the positions ...
3
votes
0answers
95 views

Sowing Once into Each of Many Lists – Any Better than Append?

In general I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
0
votes
2answers
49 views

How to generate multiplication tables up to nxn?

I'm doing a simple multiplication table and I have this that I'm having a hard time with. I imagine that there must be a shorter way to do it, what I can't get is that it paints black the first column ...
5
votes
2answers
138 views

change order element of a list in a particular order [closed]

I have this list : {0, 1, 2, 3, {0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 3}, {3, 2}, {0, 3}, {3, 0}} I would like to transform it with the following pattern : ...
2
votes
1answer
159 views

Diagonal matrix command in Mathematica

How to find the corresponding Mathematica commands for diagonal matrix operation in Matlab, e.g. AA=rand(3,3); Step 1.) finding the diagonal elements, and export ...
1
vote
2answers
34 views

A list of the exponents of the irreducible factors in a factored polynomial

I have a list of factored polynomials: {x^3, x^2 (1 + x), x (1 + x)^2, x (1 + x + x^2), (1 + x) (1 + x + x^2), 1 + x^2 + x^3, 1 + x + x^3, (1 + x)^3} I want a ...
4
votes
1answer
52 views

Best way to write a function that randomly takes definition from list of functions?

I want to define a function based on a random choice from a list of possible functions. For example, suppose the possible functions are {Sqrt,Log}. Then I want to ...
1
vote
1answer
89 views

Problem with fitting

If I have the following data (I have updated the data): ...
1
vote
0answers
72 views

What is “Flatten” doing to my elements?

Here's some of my code. x1 results in returning the position of a list in a {{{n1}},{{n2}}...}. Im trying to flatten it such that the list reads out as {n1,n2,n3....} some how it's adding elements. ...

1
2 3 4 5
141