Computes Inner Product and Squared 2-norm

Share:

Description

dotProd computes the inner (or dot/scalar) product between two vectors.

norm2 computes the squared 2-norm of all the elements in a matrix or vector.

If the vectors are of unequal length dotProd will give a warning and then truncates the longer vector, discarding any excess elements before the computations.

Usage

1
2
3
  norm2(v1)

  dotProd(v1, v2)

Arguments

v1,v2

Two vectors

Value

dotProd returns the inner product of v1 and v2. norm2 returns the squared 2-norm of all elements in v1.

Author(s)

Johan Lindstr<f6>m

See Also

Other basic linear algebra: blockMult, crossDist, invCholBlock, makeCholBlock, solveTriBlock, sumLog, sumLogDiag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
##Create two vectors of equal length
v1 <- rnorm(10)
v2 <- rnorm(10)

##compute the inner product between the vectors
dotProd(v1,v2)
##or
sum(v1*v2)

##compute the square 2-norm of v1
norm2(v1)
##or
dotProd(v1,v1)
##or
sum(v1*v1)

##If the vectors are of unequal length the longer vector
##gets truncated (with a warning). 
dotProd(v1,c(v2,2))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.