I need to solve a tridiagonal system (positive definite, diagonally dominant) $Ax = b$ in a time stepping loop. $A \in \mathbb{R}^{N \times N}$ remains constant but $b$ changes during each time step.
I was thinking which of the following would be faster :
Compute and store $\mathbf{z_i}$ that solves $A\mathbf{z_i} = \mathbf{e_i} \; \forall 1\leq i\leq N$. Then any $b \in \mathbb{R}^{N}$ is a linear combination of $\mathbf{z_i}$ and $x = b_i \mathbf{z_1} + \dotsb b_N \mathbf{z_N}$
Naively solve $A x = b$ for each given $b$ by tridiagonal matrix algorithm.
I thought (1) will save the time taken for computing the tridiagonal solves since the $z$ essentially gives the inverse of $A$. However, I calculated that one solve for $\mathbf{e_i}$ takes $8N$ flops, so that is $8N \times N$ to compute all the $\mathbf{z_i}$. Then for each given $b$, it takes $N^2$ flops to compute $x$. If I take $n$ time-steps, that is a total of $8N^2 + nN^2$.
In contrast (2) needs $n\times 8N$.
Am I correct ? Where is (2) gaining the advantage ?