vector addition with evalm?

I have to vectors with each 1000 values

when I want to make addition of both I get:

C:=evalm(A+B);

Error, (in rtable/Sum) invalid arguments. How can I do it else?

Scott03's picture

VectorAdd

If you want to add two vectors of the same size, try using LinearAlgebra[VectorAdd].

-Scott

edgar's picture

works for me

Maple 12, both of these work:

A := vector([a,b,c]); B := vector([1,2,3]);
evalm(A+B);
A := Vector([a,b,c]); B := Vector([1,2,3]);
evalm(A+B);

acer's picture

code

It's difficult to answer this well, without knowing what your code does. You may need to paste or upload an example of it going wrong for you.

Some advice can still be given:

  • Vector() is different from vector().
  • evalm() is not appropriate for uppercase Vector or Matrix.
  • A+B should work directly for Vectors A and B. (It's a shortcut to LinearAlgebra:-VectorAdd.)
  • row Vectors are different from column Vectors.

The error message "invalid arguments" from rtable/Sum arises when one attempts to add mismatched objects. For example,

> V1:=Vector(2):
> V2:=Vector(5):
> V3:=Vector[row](2):
> M:=Matrix(1..2,1):

> V1+V2: # size mismatch
Error, (in rtable/Sum) invalid arguments
> V1+V2[1..2]:  # ok

> V1+V3: # orientation mismatch
Error, (in rtable/Sum) invalid arguments
> V1+V3^%T:  # ok

> V1+M: # object mismatch
Error, (in rtable/Sum) invalid arguments
> V1+convert(M,Vector): # ok

Did I see you using Statistics in another post? It produces row Vectors, while the default for the Vector() constructor is column vectors. Perhaps that is your issue.

> with(Statistics):
> V := Sample(Normal(0,1),2);
              V := [-0.479341933636560025, 0.784173699733298979]
 
> op(0,V);
                                  Vector[row]
 
> type(V,'Vector[column]');
                                     false
 
> type(V,'Vector[row]');
                                     true
 
> type(V,'Vector');
                                     true
 
> V + Vector(2,[a,b]);  # orientation mismatch
Error, (in rtable/Sum) invalid arguments

> V + Vector(2)^%T;  # transpose either, to match
                 [-0.479341933636560025, 0.784173699733298979]
 
> with(LinearAlgebra):
> V + Transpose(Vector(2));  # transpose either, to match
                 [-0.479341933636560025, 0.784173699733298979]

acer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}