mathematical optimization - Speeding up automatic symbolic jacobian creation in Matlab -


i have code creates set of equations based on nodal coordinates in cartesian space. create jacobian based on these using automatic sym generation , series of nested anonymous functions. understand not effective way perform operation, other idea have .m files written , implemented @ runtime. here's sample of equations , methodology use.

% c created graph, here associated c example c=[[1,-1,0,0,0,0];[0,1,-1,0,0,0];[0,0,1,-1,0,0];[0,0,0,1,-1,0];[0,0,0,0,1,-1];[1,0,0,0,0,-1];[0,1,0,0,-1,0];[1,0,0,0,-1,0];[0,1,0,0,0,-1];[0,1,0,-1,0,0];[0,0,1,0,0,-1]]; % base system, 6 nodes in 2d xsys = [[0 1 2 2 1 0]' [1 1 1 0 0 0]']; dexample = rand(6,2)*0.1; % xsys in case n d matrix of coordinates (nodes dimensions)  %  , d displacement of xsys u = @(d) c *(xsys(:,1)+d(:,1)); v = @(d) c *(xsys(:,2)+d(:,2)); u = @(d) diag(u(d)); v = @(d) diag(v(d)); linv = @(d) diag(1./sqrt(u(d)*u(d)+v(d)*v(d))); l0inv = linv(xsys); q = @(d) ea*(l0inv - linv(d))  % created sake of differentiation dd = sym('d%d%d',size(xsys),'real');  % , b here sparse 0/1/-1 matrices. applying load matrix %  (same size xsys) vector fe eq1 = @(d) a' * b' * q(d) * c * (xsys+d) + * fe;  % eq1, in particular case, creates matrix of 8 equations using %  total of 12 variables contained in d j1 = @(d) [reshape(diff(eq1(d),dd(1)),[8 1])';            reshape(diff(eq1(d),dd(2)),[8 1])';            reshape(diff(eq1(d),dd(3)),[8 1])';            reshape(diff(eq1(d),dd(4)),[8 1])';            reshape(diff(eq1(d),dd(5)),[8 1])';            reshape(diff(eq1(d),dd(6)),[8 1])';            reshape(diff(eq1(d),dd(7)),[8 1])';            reshape(diff(eq1(d),dd(8)),[8 1])';            reshape(diff(eq1(d),dd(9)),[8 1])';            reshape(diff(eq1(d),dd(10)),[8 1])';            reshape(diff(eq1(d),dd(11)),[8 1])';            reshape(diff(eq1(d),dd(12)),[8 1])'];  % varargs2fun outputs argin argout objective = @(d) varargs2fun( eq1(d), j1(d) ); 

i perform optimization set values output @eq1 0, based on load application fe. procedure takes 200 seconds, majority of spent in mupadmex. help? need drop order of time 5 or 6...

again, goal jacobian automatically created, because variables b , c change, , affect number of equations in @eq1


Comments