changed code for dx=0.1, run out of memory on macbook