Q:

How to vectorize a sum of dot products between a normal and array of points

I need to evaluate following expression (in pseudo-math notation):

∑ipi⋅n

where p is a matrix of three-element vectors and n is a three-element vector. I can do this with for loops as follows but I can't figure out
how to vectorize this:
p = [1 1 1; 2 2 2];
n = [3 3 3];
s = 0;
for i = 1:size(p, 1)
    s = s + dot(p(i, :), n)
end

A:

Why complicate things? How about simple matrix multiplication:
s = sum(p * n(:))

where p is assumed to be an M-by-3 matrix.

