A few optimization techniques
There are a few things you should consider when you wish to optimize your Octave code. Some of these are:
1. Avoid loops, especially nested loops, whenever possible. Always try to vectorize your code!
2. Use Octave's built-in functionality. For example, do not try to implement your own linear equation solver because it is unlikely that you can do better than Octave.
3. Instantiate your array variables before entering a loop in order to minimize memory reallocation and therefore communication overhead with the operating system.
4. If you do partial vectorization, loop column-wise.
5. Clear large arrays whenever you are finished using them. In this way, you avoid using the slower parts of the chip memory.
6. In some situations, functions can execute faster than scripts. So it can be helpful to convert a large script to a function if it is called many times. This is because functions are read only once per Octave session (when they are called for the first time), whereas...