how to generate a matlab file from a function with small memory size ?

1 vue (au cours des 30 derniers jours)
GHA
GHA le 19 Mar 2016
Currently I running a matlab code to generate a Jacobean matrix of size 14 x 14 using symbolic expressions. I want to use the Jacobean matrix directly on other separate function. So I need to generate a file for this matrix using the following code;
J = jacobian(r,v); % the jacobean matrix to be executed
--------------------------------------------
matlabFunction(J,'File','ja.m','Vars',h); % the code I wrote to generate the file
when I run the above codes it takes so long time ( more than a night in my core i5 Hp laptop and I aborted it afterwards) and when i did run in my professor's office desktop, it took above 1 hour and 30 minutes and gives a file of size 33KB. Then I modified the code by disabling the optimization as follows;
matlabFunction(J,'File','ja.m','Vars',h,'optimize',false);
and I got the file but very very big size of 55 MB which is about 1000 times larger than the file I got from the professor. When i tried to open it, i got a warning saying "out of memory" and the i increased the heap memory. Finally I opened the file, but my PC froze and got a warning of " Matlab encounters an internal error".
The other the problem I am encountering is when I try to run other functions that call the Jacobean matrix within them, it takes more time. Any tips ?

Réponses (1)

Walter Roberson
Walter Roberson le 20 Mar 2016
Break up your Jacobian. For example take the derivative with respect to one variable at a time. This will greatly reduce the size of the expression to be simultaneously optimized. Generally speaking, the optimization process can increase in time ("cost") at least as fast as the square of the size of the expression being optimized, as each part has to be compared to each other part hoping to find a duplicate that can be eliminated.
If you need to have a single function that implements the whole derivative, then you can write a function that calls each of the single-variable functions and puts the results together in a matrix.
My personal guideline for symbolic matrices: if you go beyond about 7 x 7, then the risk rises sharply that you will run out of memory, run out of time, or run out of patience.

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by