The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [index]

Questions about functions with intrinsic part index such as SparseArray, Part and Indexed or iteration variable indexes such as MapIndexed, Sum and Product.

Filter by
Sorted by
Tagged with
0
votes
1answer
71 views

Integer functions indices in a sum

I have some troubles with plotted A versus p, especially for the function F(s,l,p), I don´t know how deal with the integer functions indices of the sum. How can I input such a sum to Mathematica?. ...
13
votes
2answers
366 views

Map vs. Table for index-specific operations on 2D arrays

Many experienced users on this site tend to use Map (and its variants, MapAt, MapIndexed, etc.) rather than Table. When applying the same operation to every element of an array, Map does seem more ...
8
votes
2answers
136 views

Function over a list that depends on the index

Suppose I have a list {a, b, c, d} I want to operate on this list with a function which depends on the index of the element, e.g. I want to add the index ...
3
votes
3answers
112 views

Is there an easy way to index by a binary vector / mask?

I would like to be able to extract elements from a list where indices are specified by a binary mask. To provide an example, I would like to have a function ...
1
vote
2answers
70 views

Collecting terms from expression with indexed functions

Say I have an expansion of terms containing functions y[j,t] and its derivatives, indexed by j with the index beginning at 0 ...
0
votes
0answers
38 views

Creating lists of values referring to the same index

I would like to code lists of the form: Ai = {x0, x1, x2, x3, ...} Bi = {y0, y1, y2, y3, ...} where the index i refers to the elements 0,1,2,3, etc., across all lists that I make. The values in the ...
1
vote
0answers
46 views

Typography of Mixed Tensor Index Notation

How can one properly and quickly write a mixed "tensor" such as $\Gamma{}_{1}{}^{2}{}_{3}$? Shortcuts such as esc Gamma esc, Ctrl+^, Ctrl+_ are prefered. I intendd to use this in an inline equation ...
1
vote
1answer
57 views

Create list of values with arbitrary index and the use it in a function

I have the following generating functions: $l_{2i-1}=l_{1}-(i-2)(w+s)$ with $i\geq 2$ and $l_{2i}=l_{2}-(i-1)(w+s)$ with $i\geq 2$, so the first one is for odd index and the second for even index. ...
1
vote
0answers
165 views

Sum over multiindex

I would like to calculate a sum over some multi-indices, that follow a specific pattern. $$\sum\limits_{1\le i_1<i_2<...<i_k\le N} A(k,i_1, i_2, ..., i_k).$$ $A$ is a fix expression of the ...
0
votes
0answers
20 views

Why do I have to index my covariance matrix as if it has 3 dimensions [duplicate]

The language reference for getting parts of a matrix seems to make sense. I'm wondering why my covariance matrix behaves differently. ...
2
votes
0answers
62 views

ParallelDo with doubly-indexed iterators

What is the reason that ParallelDo works with singly-indexed iterators, but not doubly- or more-indexed iterators? For example, the code ...
0
votes
0answers
43 views

Defining list of data

I need to define a list of parameters A[i] where i runs from 1 to some integerN. The ...
0
votes
2answers
88 views

Algorithm for Swapping indices and simplifying the summand in a double sum [closed]

Say we have something like $$ \sum_{p}^N\sum_{q}^N \cos(p) \sin(q) - \cos(q)\sin(p) $$ usually, in the case like this, the indices p and q can be swapped, and the sum simplifies to 0. I have an ...
3
votes
2answers
322 views

Indexing nested list with another list

So I'm wanting to index the sublists within a list using another list. So I have x = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} And I want the 2nd term of the first ...
1
vote
2answers
447 views

Finding the x-value corresponding to a y-value found using Nearest [closed]

I have a large 2d array of infinite precision named "data" of x values and y values. I am using Nearest to find the y-value closest to a specified number, say 0....
1
vote
1answer
113 views

subscript index notation select certain value [closed]

I have an indexed variable Subscript[p, s, m, t] established using the Notation method. There are various expressions where s, <...
2
votes
0answers
38 views

Part[] for multi-index array [duplicate]

If I want to set element (i,j) of two-dimensional array X to 0, I can write X[[i,j]] = 0. My question is how can I achieve this if I have the indices i and j in a ...
7
votes
2answers
317 views

Add Index to All Elements of a List

My goal is to add an index to all elements of a list in the form {"a", "b", "c", ... }, so it becomes ...
4
votes
1answer
558 views

How to use the value returned from Position as index for another list? [duplicate]

say, I want to find an index of a specific element in a list using Position[{a, b, c, d, e, f}, c] and it returns {{3}} How ...
0
votes
1answer
320 views

Getting error messages during double summation [closed]

I have two lists xi and ai of equal length, n. I would like to perform a sum over the ...
2
votes
2answers
56 views

Condition on the index of an element $a_{i,j}$

This question may seem to be easy. But I did not find the right way after several attempts I need to put a condition in general for $a_{i,j}$ ,If the i is bigger ...
6
votes
2answers
118 views

Using sparse matrices when value depends on position

I am working with solving a linear system that becomes a tridiagonal matrix. In order to speed up the process for large matrices, I want to use sparse matrices. My problem is that the values are not ...
3
votes
2answers
124 views

How to convert span to flat list of indices?

Let sp be a Span object, and n a non-negative integer. I'm looking for an efficient way to ...
5
votes
1answer
1k views

How to parse JSON

please forgive me if this is obvious, but I have some JSON: ...
2
votes
1answer
220 views

contraction of indexes takes long time

I have got an expression which has more than a hundred terms being added up together, each of terms are similar in mathematical form....
9
votes
2answers
178 views

Unable to use indexed variables with NDEigensystem

I am trying to solve a system of differential equations with NDEigensystem, but there need to be arbitrarily many of them. I want to use indexed variables like a[i], which works fine with NDSolve, but ...
0
votes
2answers
45 views

How can I retrieve an element of an array created with Range? [duplicate]

I have the following Mathematica code where I create a linearly spaced array of numbers and try to retrieve the third element: ...
3
votes
2answers
145 views

How to map functions twice?

I would like to plot multiple lists. The table looks like a={{1,2,3,0,0,0,0,0,0},{1,2,3,0,0,1,0,0,0},{1,2,3,0,0,0,2,0,0},...,{1,2,3,0,0,0,0,3,0}} I want to plot ...
2
votes
2answers
715 views

How to set variable from imported data

I have an excel file i would like to import as data in mathematica with 3 columns like below: Column 1: the nodal numbers Column 2: the values of mx Column 3: the value of mxy Once ive imported the ...
3
votes
1answer
215 views

Using a set of indices to select a subset of an array

Let's say I have a 1D array a, I can use a list of indices b to select a subset of that array: ...
9
votes
2answers
208 views

Slicing an Association with named key span without normalizing?

Is there way to slice an Association with named key span? Span currently doesn't accept named keys: ...
-1
votes
1answer
51 views

How to use Table function with two parameters executed when they are not equal? [duplicate]

I have a list, param2 = { {-qlim, -qlim}, {-qlim, qlim}, {qlim, -qlim}, {qlim, qlim} }; and want to get combination of them with, ...
2
votes
2answers
663 views

define variable index

im in the medal of coding and i reached the point where i have something like this, the problem is i have up to 35 terms and all should be index in order to preform summation to count all ...
3
votes
1answer
40 views

Fast list update using list of indices with repetitions

I want to update a vector like this: list = {0, 0, 0, 0}; updval = {1, 1, 1}; updind = {2, 2, 3}; list[[updind]] += updval; list The result is ...
7
votes
2answers
220 views

What's wrong with the Sum function?

Here are the codes: ...
1
vote
0answers
156 views

Assigning Values of Indexed Variables to Arrays

New to mma. I have assigned the results of using Solve to solve 5 variables to 5 indices of a new variable: ...
11
votes
3answers
260 views

Basic Search Functionality

Let say I have three blocks of text like the following. {"first block of text with random content","different block of text","1 2 3 4"} Now let's say I want to ...
5
votes
1answer
220 views

An alternative to subscripts?

Are there any good alternatives to using subscripts to keep track of and uniquely identify many variables? I know that subscripted variables behave badly. Thanks!
2
votes
2answers
235 views

Define a 4d matrix without for loop

I was wondering if there is a way to avoid for loop here: I want to define a 4d matrix H(i,j,k,l), and each entry in the matrix is calculated through a complex function, say Do_H(i,j,k,l), depending ...
5
votes
4answers
188 views

Multi-index variable depending on signature of permutation of indices

I do have some multi-indexed variable, e.g. like this \begin{align*}f_{123} &= 1\\f_{345} &= 1/2\end{align*} where $f$ is antisymmetric under permutation of any pair of indices, i.e. e.g. $...
0
votes
0answers
81 views

Workaround of non-integer indexed objects? [duplicate]

When using indexed object, I found the behavior of value 0.7 as the index quite strange, then did the following test. The first output cell was executed directly as the second input cell. Have not ...
0
votes
3answers
991 views

What would be a good way to implement index notation?

So I need to calculate a 3x3 rotation operator (basically a matrix). I have an index-notation expression, and I was wondering if with pre-calculated theta, K1, K2, and K3, could Mathematica compute ...
4
votes
1answer
135 views

Assign zeros to large list of indexed variables

I have a big list of the form list={P[1,1],..,P[i,j]} and would like to assign 0 to each of them, but ...
7
votes
1answer
420 views

Why does this simple sum function fail to compile?

Consider the following compiled function, which takes a $12 \times 5$ array $x_{ij}$ of real numbers and computes the triple sum $$ \sum_{k=1}^5 \sum_{i=1}^{12} \sum_{j=i+1}^{12} x_{ik} x_{jk}. $$ <...
28
votes
5answers
2k views

What are the requirements for a well behaved indexed variable? Subscript, ToExpression, Downvalue?

On writing this answer I needed to call a function, (NonlinearModelFit) with an unknown number of parameters. We have learned that we should not use ...
-1
votes
1answer
156 views

Position not working? [closed]

I have the list: myList={0,0,0,a,b,c,0,0,d} I need to find the positions of all elements that are non-zero. I do like this: ...
3
votes
1answer
142 views

How should I enter indexed terms? For example, constants $n_k$ for $k\in\{1,\,\ldots,\,N\}$

How should I enter $\quad \quad \sum^{N}_{k=0}{f(n_k)}$ into Mathematica? More generally, how should I work with the indices? Take the following as an example. I know how the ...
31
votes
2answers
6k views

Why do Mathematica list indices start at 1? [closed]

In most programming languages, container indices start at 0. This is not random or hardware-related; for example Dijkstra's article explains why zero-based indices make sense. What are the reasons ...
1
vote
1answer
96 views

Tiny question about Indexed[x,n]

Maybe I should apologize for this silly question, but the documentation for Indexed is very short and not explicit. I have an equation with variables ...
2
votes
1answer
581 views

How to swap tensor indices without permutation?

Say I have a tensor of rank R, How to swap $i^{th}$ and $j^{th}$ tensor index? I do not want to use TensorTranspose because it requires to write down the entire permutation, i.e. TensorTranspose[T,{1,...