How to store a matrix of values and pick out certain elements and compute the difference? I at the moment am trying to make an EV3 robot which is capable of following a gradient decent method. The idea was to store a discretized function in a 2D matrix, and make several lookups in that 2D matrix where I compute the difference between its position and its neighbor's position. and then make the robot move in the direction with descending gradient. 

To do so... 

How do I use the EV3 software to:


Create a Matrix?
Store values in matrix?
Make lookups in matrix?
Subtract those lookups?


This could be way easier in C++, but is there any supported firmware capable of running C or C++ in the same way as with NXC or something like this? Something with some form of documentation?
This application does seem to be pushing the limits of the official software provided by LEGO. If you are interested in C/C++ (or any other programming language), check out http://www.ev3dev.org.

I like to say that ev3dev is not firmware since it runs from a microSD card and is not loaded into the flash memory on the EV3. Nevertheless, it is an alternate operating system for the EV3 with the goal of being able to program in any language that you like. You can find a list of existing programming libraries here.