Theory and numerical calculation of pattern formation in shrinking gels