So you mean try every value for n that seems reasonable, perform the optimization routine for each one, then calculate the resulting functional for each case, compare all of them by hand, and choose the one that is optimal?
To be honest, the whole thing seems more convoluted than it ought to...