Dean
Dean

Reputation: 6960

Octave - exponentiation with square matrix

Why does in Octave the following

X = ones(10, 10)
X ^ 2

yields a 10x10 matrix with all elements set to 10?

I was not expecting this but rather having all elements squared (and therefore a matrix of 10x10 1 elements)

Upvotes: 0

Views: 4995

Answers (1)

marcolz
marcolz

Reputation: 2970

If you want the ^ operator to be applied element-by-element, use .^

Otherwise you will be doing matrix multiplication.

Upvotes: 2

Related Questions