avatar
t*n
1
matlab进行矩阵运算很快,尽量避免loop循环。可是下面这个问题有什么好办法解决呢?
对很多位置坐标进行下面的运算
sigma = [x y] * cov^-1 * [x y]'
cov是2x2矩阵
是不是只能用for语句每次进行一个坐标的运算?有没有办法对所有的坐标同时进行以
提高速度?谢谢。
avatar
r*y
2
If cov is 2x2, then it's easy to directly write down elements
just use cov instead of cov^-1 for illustration
[x y] * cov = x * cov11 + y *cov21, x * cov21 + y * cov22
then
[x y] * cov * [x y]' = x (x * cov11 + y * cov21) + y (x*cov21 + y*
cov22)
So now if you have a large array of x, and y, assume they are both
[n, 1] arrary
then your sigma
sigma = x .* ( cov11 * x + cov21 * y) + y.* (cov21 * x + cov22 * y)
note, co

【在 t******n 的大作中提到】
: matlab进行矩阵运算很快,尽量避免loop循环。可是下面这个问题有什么好办法解决呢?
: 对很多位置坐标进行下面的运算
: sigma = [x y] * cov^-1 * [x y]'
: cov是2x2矩阵
: 是不是只能用for语句每次进行一个坐标的运算?有没有办法对所有的坐标同时进行以
: 提高速度?谢谢。

avatar
t*n
3
very smart way. exactly what I want. Thank you!
Some comments below.

cov12
[x y] * cov * [x y]' = (x * cov11 + y * cov21)x + (x*cov12 + y*
cov22) * y
cannot or can? I think it's can, right?
行以

【在 r****y 的大作中提到】
: If cov is 2x2, then it's easy to directly write down elements
: just use cov instead of cov^-1 for illustration
: [x y] * cov = x * cov11 + y *cov21, x * cov21 + y * cov22
: then
: [x y] * cov * [x y]' = x (x * cov11 + y * cov21) + y (x*cov21 + y*
: cov22)
: So now if you have a large array of x, and y, assume they are both
: [n, 1] arrary
: then your sigma
: sigma = x .* ( cov11 * x + cov21 * y) + y.* (cov21 * x + cov22 * y)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。