ilker
ilker

Reputation: 25

Product a scalar with a matrix in mathematica

I want to product a scalar with a matrix in mathematica. My codes are :

w.P + (w^3).P

P is a matrix and w is a scalar, but product gives scalar out of the matrix. Why?

Upvotes: 1

Views: 3133

Answers (1)

Codie CodeMonkey
Codie CodeMonkey

Reputation: 7946

The . operator is specifically for tensor (including vector and matrix) multiplication. Just multiply without the .:

w P + (w^3) P

I can't explain your statement that the product as you have it yields a scalar. For example:

P = {{1, 2}, {2, 3}};
w = 5;
w.P

Gives the result:

5.{{1, 2}, {2, 3}};

since Mathematica hasn't defined what Dot[a, b] means when a is a scalar and b is a matrix. (You could actually define this yourself if you like.)

Upvotes: 2

Related Questions