Creating walls to avoid unwanted points in root finding and optimization