I want to calculate the geometric series of a matrix $A$:
$$S=I+A+A^2+\dots+A^n$$
and then apply to a vector $v$, $Sv$.
I've done it in Matlab with a loop and I think it's quite efficient applying the matrix $A$ to $v$ at each step instead of calculating $S$ first.
Anyway, I tried to compute the series using $S=(I-A^n)(I-A)^{-1}$, but when calculating the inverse I get an error because $A$ is nearly singular.
Is the an efficient way to compute the inverse in this case? I thought it would be better than a loop since Matlab is quite good manipulating matrices.
I know that $A$ has dominant diagonal and tridiagonal.