开发者

Matlab Question on Sparse Matrices

开发者 https://www.devze.com 2023-02-14 22:09 出处:网络
I have a sparse matrix S. I perform the following operation D1 = diag(sum(S,2)), basically forming a diagonal matrix.

I have a sparse matrix S. I perform the following operation D1 = diag(sum(S,2)), basically forming a diagonal matrix. Now I need to perform (D1)^(-0.5), but I get an error "Error using mpower, use full(x)^full(y)"

Converting to full will defeat the purpose of using a spa开发者_Go百科rse matrix.

Any advice will be very helpful.


Raising a diagonal matrix to a power can be done simply by doing the operation on the diagonal elements elementwise... so:

D1_diagonal_elements = sum(S,2);
your_result = diag(D1_diagonal_elements .^ (-0.5));
0

精彩评论

暂无评论...
验证码 换一张
取 消