Ask Your Question
0

Matrix / Vector multiplication fails

asked 2024-12-07 14:25:10 +0100

Cyrille gravatar image

I want to obtain the following matrix/vector multiplication

> A=[[2.36,2.68,6.78,20.37,2.34],
> [4.14,2.64,7.2,18.47,4.21],
> [4.98,3.68,10.91,19.90,4.20],
> [8.8,5.73,19.43,29.03,8.09],
> [13.51,12.64,24.44,27.59,13.93],
> [21.64,18.49,29.15,38.01,20.19],
> [30.57,30.57,38.04,34.14,23.47],
> [40.51,40.51,39.36,20.93,36.27],
> [42.42,42.42,43.80,23.52,48.13],
> [34.82,34.82,55.19,28.7,41.39],
> [22.25,22.25,52.15,32.81,32.81],
> [31.86,31.86,51.49,37.36,48.86]];
> 
> M = transpose(matrix(A)); 
>  show(M)
> io=vector(RR,[1. for i in range(len(M.rows()))]);
> show(io)
> nr=M.nrows() (1/nr)*M*io

and I have the following error

"unsupported operand parent(s) for *: 'Full MatrixSpace of 5 by 12 dense matrices over Real Field with 53 bits of precision' and 'Vector space of dimension 5 over Real Field with 53 bits of precision'". I don't understand where is the problem. Dimensions are correct and matrix and vector are defined on the same field and there is no problem with the following code.

A = matrix([[1.12,2.34],[3.24,4.53]]);
b = vector([1,1]);
show(A*b)
show(b*A)
edit retag flag offensive close merge delete

Comments

Btw, you can use M.nrows() instead of len(M.rows()), and io = vector(RR,[1.]*M.nrows()).

Max Alekseyev gravatar imageMax Alekseyev ( 2024-12-07 14:38:46 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-12-07 14:32:29 +0100

Max Alekseyev gravatar image

updated 2024-12-07 14:33:12 +0100

Dimensions do not match for multiplication M*io, which requires the number of columns of M equal the size of io. You can do io*M though.

edit flag offensive delete link more

Comments

Thanks Max,but what I want is M*transpose(io). But, to my knowledge, there is no transposition for a vector.

Cyrille gravatar imageCyrille ( 2024-12-08 23:14:38 +0100 )edit

M*transpose(io) still have mismatching sizes. For it to work M should have number of columns equal 1, which is not the case. The consistent sizes in your example have A*io or io*M, which are equivalent given that M = A.T.

Sage does not support transposing vectors since it does not make distinction between column- and row- vectors. That is, if M*transpose(io) worked, then so would M*io (and thus transpose() is not needed here). If you want to have column- or row- vectors, define them as $n\times 1$ or $1\times n$ matrices.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-12-09 02:17:34 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-12-07 14:25:10 +0100

Seen: 79 times

Last updated: Dec 07 '24