简体   繁体   中英

How to compute the quadratic form of 2 matrix in matlab?

Given 2 matrix A , B with the same dimension,

M(x, y) = |A(x, y).*A(x, y)  A(x, y).*B(x, y)|
          |A(x, y).*B(x, y)  B(x, y).*B(x, y)|

How to get the M in matlab?

updated

Hopefully, we can get a M with dimension (m, n, 2, 2).

Well, this is a straightforward way to do it:

M = [ A.*A  A.*B ; A.*B B.*B ]

Or did you have something more optimized in mind?

[Edit] If I understand correctly, you want a 4D result. Here is my ugly solution:

M = reshape([A(:).*A(:) ; A(:).*B(:) ; A(:).*B(:) ; B(:).*B(:)], [size(A) 2 2])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM