I am currently working on a simulink model which includes a MATLAB function block. This function block is used to evaluate an expression for a Jacobian of a complex function at a certain state. This expression for the Jacobian was derived using the symbolic toolbox and yields a very lengthy expression for each element in the Jacobian. Since the Jacobian has size 3x6 a total of 18 expressions need to be evaluated in the MATLAB function.
When running the model it takes a significant amount of time to compile (15-30min). But once complete the simulation itself is quite fast (+/- 20sec). I am trying to understand what is happening during the compiling of the model, so that I can perhaps alter the code. I already tried to find common terms in the lengthy expressions, as I expect that the compilation process might include this process, but this does not seem to speed up the compilation time. Is there any advice available as to how to reduce the time required for the compilation of a simulink model? specifically for simulink models that include a MATLAB function.