 Error, (in rtable/Sum) invalid input: dimensions do not match: Vector[column](1 .. 4) cannot be added to Matrix(1 .. 4, 1 .. 1) - Maple Help

Home : Support : Online Help : Error, (in rtable/Sum) invalid input: dimensions do not match: Vector[column](1 .. 4) cannot be added to Matrix(1 .. 4, 1 .. 1)

Error, (in rtable/Sum) invalid input

Error, (in rtable/Sum) invalid arguments Description This error occurs when trying to add or subtract two Arrays, Matrices, or Vectors that are either not of the same type or do not have the same dimensions.   The usual fix for this is to convert one of both of the elements so that they are both of the same type and/or dimension using either convert, Transpose, or the constructors for Array, Matrix, or Vector. Examples

Example 1

 >
 $\left[\begin{array}{r}1\\ 2\end{array}\right]$ (2.1)
 >
 $\left[\begin{array}{r}5\\ 6\end{array}\right]$ (2.2)
 > $M+V$

In this first example, M and V appear to be of the same type, but they are not:

 > $\mathrm{whattype}\left(M\right)$
 ${\mathrm{Matrix}}$ (2.3)
 > $\mathrm{whattype}\left(V\right)$
 ${{\mathrm{Vector}}}_{{\mathrm{column}}}$ (2.4)

When addition is attempted an error occurs.

Solution:

To solve this error, use convert on one (or both) of the elements to be added. Here, we convert V to a Matrix before adding it to M:

 > $M+\mathrm{convert}\left(V,\mathrm{Matrix}\right)$
 $\left[\begin{array}{r}6\\ 8\end{array}\right]$ (2.5)

Example 2

Here we try adding two column Vectors.

 > $Y≔⟨1,2,3⟩$
 $\left[\begin{array}{r}1\\ 2\\ 3\end{array}\right]$ (2.6)
 > $Z≔⟨4,5⟩$
 $\left[\begin{array}{r}4\\ 5\end{array}\right]$ (2.7)
 > $Y+Z$

The error occurs because Y is a 3-element column Vector and Z is a 2-element column Vector.

Solution:

To correct this error, use the Vector constructor to create a 3-element Vector using Z as the initializer for the first two elements. If the new Vector has more elements than the initializer, the remaining elements are set to zero.

 > $\mathrm{Vector}\left(3,Z\right)$
 $\left[\begin{array}{r}4\\ 5\\ 0\end{array}\right]$ (2.8)
 > $Y+\mathrm{Vector}\left(3,Z\right)$
 $\left[\begin{array}{r}5\\ 7\\ 3\end{array}\right]$ (2.9)

Example 3

Here we try adding two Arrays with different dimension.

 > $A≔\mathrm{Array}\left(\left[\left[1,2,3\right],\left[4,5,6\right],\left[7,8,9\right]\right]\right)$
 $\left[\begin{array}{rrr}1& 2& 3\\ 4& 5& 6\\ 7& 8& 9\end{array}\right]$ (2.10)
 > $B≔\mathrm{Array}\left(\left[\left[1,10\right],\left[2,20\right]\right]\right)$
 $\left[\begin{array}{rr}1& 10\\ 2& 20\end{array}\right]$ (2.11)
 > $A+B$

Solution:

Again, the solution is to use Array to construct a 3X3 Array using B as the initializer.

 > $\mathrm{Array}\left(1..3,1..3,B\right)$
 $\left[\begin{array}{rrr}1& 10& 0\\ 2& 20& 0\\ 0& 0& 0\end{array}\right]$ (2.12)
 > $A+\mathrm{Array}\left(1..3,1..3,B\right)$
 $\left[\begin{array}{rrr}2& 12& 3\\ 6& 25& 6\\ 7& 8& 9\end{array}\right]$ (2.13)

For users of Maple 18 and earlier versions: These examples resulted in a different error message.  The solutions are the same.  For example, the example 3 given above resulted in:

 > $A+B$ See Also