# How to calculate inverse of square matrix for streaming or online data as all data are not available at once?

Suppose initial data is $D$ and need to calculate the inverse of covariance of matrix $D$ i.e. $C = cov(D,D)$, where $cov$ represents covariance.

$B = inv(C)$

Now, new data $N$ appears. So matrix D and C both will updated as follows:

$D^{new} = \begin{bmatrix} D\\ N \end{bmatrix}$

$C^{new} = \begin{bmatrix} cov(D,D) & cov(D,D^{new})\\ cov(D^{new},D) & cov(D^{new},D^{new}) \end{bmatrix} = \begin{bmatrix} C & cov(D,D^{new})\\ cov(D,D^{new})^T & cov(D^{new},D^{new}) \end{bmatrix}$

Similarly, data will be updated continuously. Now, inverse of $C$ (i.e. $B$) is given and need to calculate inverse of $B^{new}$. However, I don't want to use direct or general inverse as it will be very expensive if matrix size will be large and also want to utilize the inverse calculated for old data i.e. $B$.

P.S: I have tried inverse of block or partitioned matrix but it doesn't yield similar result as general inverse in all cases ( For more detail: https://math.stackexchange.com/questions/2341605/why-i-am-getting-difference-between-block-inverse-and-general-inverse ). If someone needs then I can provide the MATLAB code to verify it.

• – Emre Jul 2 '17 at 8:24
• Thanks for ur reply. It seems, u r talking abt block inverse matrix which uses Sherman-morrison formula to solve this problem ( en.m.wikipedia.org/wiki/Block_matrix ) . However, I have already mentioned that block inverse is not working properly. If u r saying something else then plz let me know. – Chandan Gautam Jul 2 '17 at 8:47
• y ur typing ur cmmnts like ths? kinda hard 2 srsly give advnc'd math advce 2 sum1 writing like a 90s txt msg. – user1717828 Jul 2 '17 at 10:16
• Sorry for the mistake... I will be careful from the next time. – Chandan Gautam Jul 2 '17 at 12:27