Matrix-Based Multigrid:Theory and Applications