From: Etienne on 29 Jul 2010 20:15 Hi Folks I am trying to calculate the derivatiaves of a function. However, when I implement the equations in a matlab function, and then in a simulink function, the simulink model runs a lot slower. I ran the profiler and get the results at the end of the message. Line 11 does the same as 18 and 19. Why the massive difference? I have disabled the simulink autosave function, checked for writing to the workspace etc, but I am not sure if there might be other simulink settings I can try. Thanks Etienne =============================================== time calls line 1 function [f,o,dfdu,dfdp]=absimfunc(par,u,ijac) 2 % 3 % function file for demo ab 4 % 1.11 1203138 5 f=[0,0]; 0.77 1203138 6 o=[]; 0.68 1203138 7 dfdu=[]; 1.16 1203138 8 dfdp=[]; 9 130.77 1203138 10 o=feval('ab',0,u,par(1:3),'outputs'); 122.66 1203138 11 f=feval('ab',0,u,par(1:3),'derivs'); 12 0.51 1203138 13 u1=u(1); 0.51 1203138 14 u2=u(2); 15 0.97 1203138 16 e=double(exp(u2)); 17 0.52 1203138 18 f(1)=-u1 + par(1)*(1-u1)*e; 3.42 1203138 19 f(2)=-u2 + par(1)*par(2)*(1-u1)*e - par(3)*u2;
From: Steven_Lord on 3 Aug 2010 16:37 "Etienne" <etienne.coetzee(a)airbus.com> wrote in message news:i2t5ir$15f$1(a)fred.mathworks.com... > Hi Folks > > I am trying to calculate the derivatiaves of a function. However, when I > implement the equations in a matlab function, and then in a simulink > function, the simulink model runs a lot slower. I ran the profiler and > get the results at the end of the message. Line 11 does the same as 18 and > 19. Why the massive difference? I have disabled the simulink autosave > function, checked for writing to the workspace etc, but I am not sure if > there might be other simulink settings I can try. > > Thanks > > Etienne > > =============================================== > time calls line > 1 function [f,o,dfdu,dfdp]=absimfunc(par,u,ijac) > 2 % > 3 % function file for demo ab > 4 % > 1.11 1203138 5 f=[0,0]; 0.77 1203138 6 o=[]; 0.68 1203138 > 7 dfdu=[]; 1.16 1203138 8 dfdp=[]; 9 130.77 1203138 10 > o=feval('ab',0,u,par(1:3),'outputs'); Do NOT call your function using FEVAL. You _know_ what function you're calling -- so just call it! o = ab(0, u, par(1:3), 'outputs'); > 122.66 1203138 11 f=feval('ab',0,u,par(1:3),'derivs'); Ditto on the FEVAL. This also renders line 5 unnecessary, unless line 10 can somehow prematurely return from the function. > 12 0.51 1203138 13 u1=u(1); 0.51 1203138 > 14 u2=u(2); 15 0.97 1203138 16 e=double(exp(u2)); 17 0.52 1203138 > 18 f(1)=-u1 + par(1)*(1-u1)*e; 3.42 1203138 19 f(2)=-u2 + > par(1)*par(2)*(1-u1)*e - par(3)*u2; Note that lines 18 and 19 are overwriting the f that you created on line 11 [assuming that the output of line 11 is a 2-element vector] so line 11 is dead code (unless your ab function has a side effect that occurs as a part of its execution, like writing to a file or creating graphics.) -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: using .mat files in functions Next: saving different variables |