Algorithms to compute the largest invariant set contained in an algebraic set for continuous-Time and discrete-Time nonlinear systems