MEX to improve a recursive computation

1 view (last 30 days)
polt
polt on 12 May 2014
Hi everybody,
I have a simple function of the form:
function t = RungeKutta_secondorder(c1,c2,w0,dcr,d0,E)
dw=0;
d=d0;
dt=0.001;
t=0;
while d<dcr
kp1=0.5*(c1-(E*sin(d)/c2))*dt;
kpp1=w0*dw*dt;
kp2=0.5*(c1-(E*sin(d+kpp1)/c2))*dt;
kpp2=w0*(dw+kp1)*dt;
t=t+dt;
dw=dw+0.5*(kp1+kp2);
d=d+0.5*(kpp1+kpp2);
end
end
The typical values for the arguments are: c1=0.4,c2=6,w0=300,dcr=1.1,d0=0.3,E=1.
Another program calls this function many many times. Therefore, it is very important to reduce its computation time to the least possible. How can I achieve this goal by MEX and/or filter techniques?
with MEX I mean including a MEX function instead of the above piece of code (I do not know how to write that MEX).
with filter I mean the filter command in signal processing toolbox which is sometimes used to speed up recursive computations (I do not know how to use it instead of the above function).
Thanks a lot,

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!