/ComputeControl.m

https://bitbucket.org/ThomasChaffey/open-loop-ccm · Objective C · 22 lines · 21 code · 1 blank · 0 comment · 5 complexity · f7fcfc40d29660ed36226530f2ac4459 MD5 · raw file

  1. function [ut] = ComputeControl(ct, s_int, kd)
  2. % Integrate controls using the Trapezoidal rule and approxmiate derivatives.
  3. % kd is a function handle to a function that calculates kd - kdsquared
  4. % for delta^2 CCM, kdfourth for delta^4 CCM.
  5. ut = zeros(1/s_int + 1,1);
  6. for s = s_int:s_int:1
  7. e = round(s/s_int + 1); % end index for current s
  8. % calculate end derivatives using skewed stencils
  9. derivative0 = (ct(2) - ct(1))/s_int;
  10. derivativen = (ct(e) - ct(e - 1))/s_int;
  11. ut(e) = 0;
  12. ut(e) = ut(e) + kd(derivative0);
  13. ut(e) = ut(e) + kd(derivativen);
  14. for i = 2:e-1
  15. % calculate derivative using centered stencil
  16. derivative = (ct(i + 1) - ct(i - 1))/2/s_int;
  17. ut(e) = ut(e) + 2*kd(derivative);
  18. end
  19. ut(e) = s_int/2 * ut(e);
  20. end
  21. end