I am coding an evolutionary optimization program in Matlab. I want all the variables to have limited number of decimal points. (The reason is to reduce the search space. For e.g., if 1 < x < 2 , I will have only 9 options for x if the number of decimals is fixed to one.) Using 'round' is okay, but computationally a bit expensive. I see that 'digits' fix, but in the memory it saves all the digits.
Any help is appreciated, Many Thanks in advance, Ahammed
The way fixed-width optimisation is usually done is using large integers instead. For example, if you want to limit your computations to 6-digits precision, then you can just truncate all values multiplied by a million.
Arithmetic operations on integer types are fast and exact, compared with floating-point numeric formats. I'm not sure you would gain anything in terms of efficiency in Matlab though, given that numeric types usually default to double
and that most functions require either double
or single
inputs.