Subtracting or adding vectors in a matrix

Viewed 105

I am trying to subtract vectors of a matrix. In other words suppose that I have matrix A with elements

x1    x2    x3    x4
y1    y2    y3    y4
z1    z2    z3    z4

I want to be able to subtract vectors

x1  
y1
z1

and

x2
y2
z2

How would I be able to do this? I tried doing

implict none
real, dimension(3,4) :: A
real,dimension(3) :: vector
vector(1)=A(1,1)-A(1,2)
vector(2)=A(2,1)-A(2,2)
vector(3)=A(3,1)-A(3,2)

However, this is rather crude. Also, this method would be impractical if I need to compute several sums or residues, especially when the matrix is very large. I want to be able to do it more elegantly.

Is there a way to specify a vector inside a matrix? Or is there a roundabout way to do this?

1 Answers
Related