Use stack variable instead of global when computing matrix