I am running an optimization that is taking too long.
As I profiled my code, I figured out that what is taking most of the time is one line of code that is evaluating a variable. Everything is in vector form (relatively big one) and that line of code is also pretty long (pages).
First thing that crossed my mind was to symbolically simplify the equation, to make it shorter and to [hopefully] reduce the number of operations.
The second thing I did was to see if I have any term with those vectors being to power of something. I precalculated them and used the precalculated values in this line of code instead (for example E2 = E.^2, E3 = E2.*E and so on). I thought this should help because I have hundreds of these instances - even though I am creating and storing new variables (turned out to be not a big help though).
I was wondering if anyone thinks of any other method to make my code faster. I have done columns vs rows already for storing the vectors.
I was also wondering if I can have Matlab find terms that have repeated often without I inspect pages of code myself. For example, if (v+1)^2 is repeated, so I can precalculate it and save some time.
Any help will be appreciated.