Error, bad index into Matrix - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Error Message Guide : badindexintoMatrix

Error, bad index into Matrix

Error, bad index into Array

Error, bad index into Vector

Description

Indexing into a Matrix, Array, or Vector must be done with integer values. Related to this, multi-element selection with a Matrix, Array, or Vector must also come down to integers at the endpoints. Trying to index a Matrix with a symbol will result in an error.

Examples

Example 1

Note that n has no value in this example.

 

A  1,2 ; 3, 4 

A:=1234

(2.1)

An,n

Error, bad index into Matrix

 

Solution:

In this case, defining n  corrects the error.

n1

n:=1

(2.2)

An,n

1

(2.3)

 

Example 2

This one is more subtle because the sum command is following Maple's normal evaluation rules. The index operation Vi is attempted before sum is called.  At this point, the name i does not have a value.

 

V  1,2, 3,4

V:=1234

(2.4)

sumVi,i=1..4

Error, bad index into Vector

 

Solution 1:

Evaluation of  Vi needs to be delayed using right single quotes.   

sum 'Vi', i=1..4 

10

(2.5)

 

Solution 2:

Instead of sum, use add.  The add command is recommended for adding a finite sequence of values.  The add command has special evaluation rules, so no error occurs in the evaluation.

add Vi, i=1..4 

10

(2.6)

 

 

Example 3
A nested call to sum with only one set of right single quotes leads to a different error. A second set of right single quotes corrects the problem.

 

A  Matrix3,i,ji+j

A:=234345456

(2.7)

sumsumAi,j,i=1..3,j=1..3;

Error, bad index into Matrix

sumsum'A'i,j,i=1..3,j=1..3;

Error, (in tools/add) bad index into Matrix

 

Solution:

sumsum' 'A' 'i,j,i=1..3,j=1..3;

36

(2.8)

See Also

add, Matrices and Vectors, uneval


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam