function - Run Speed in Matlab -


i have written slow code , want make faster. think must time consumer part below part called function (f_xy). there simple way make code faster part? (length(t) approximately 1000000.)

 i=1:(length(t)-1)                              % calculation loop k_1 = f_xy(t(i),xx(i),aa,bb,l,t,k,f,d,del);  k_2 = f_xy(t(i)+0.5*h,xx(i)+0.5*h*k_1,aa,bb,l,t,k,f,d,del); k_3 = f_xy((t(i)+0.5*h),(xx(i)+0.5*h*k_2),aa,bb,l,t,k,f,d,del); k_4 = f_xy((t(i)+h),(xx(i)+k_3*h),aa,bb,l,t,k,f,d,del); xx(i+1) = xx(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;    % main equation `end`  

function below:

function fp = f_xy(t,r,aa,bb,l,t,k,f,d,del) w_0 = @(r) aa * ( sin(2*pi*r/l) + (del/4)*sin(4*pi*r/l)) + bb; ww_0 = @(r) (2 * pi * aa / l) *( cos(2*pi*r/l) + (del/2) *cos(4*pi*r/l) ); ff = @(r) -d / (k * t * sqrt(1 + ww_0(r)*ww_0(r))); ss = @(r) - t * k * (ww_0(r)/w_0(r)); index = round(t); if(index > 0 && index <= length(f))  fp = ff(r)*(f(index) + ss(r));] else error('index out of bounds'); end end 


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -