Advertisement
Guest User

mycontroller

a guest
Sep 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. function [z,i] = mycontroller(x) %#codegen
  2. %Evaluate function "primal" via a binary search tree
  3. %
  4. % [value, region] = mycontroller(x)
  5. %
  6. %See "help BinTreePolyUnion/toMatlab" for more information.
  7. x=x(:);xh=[x;-1];
  8. if numel(x)~=2,error('The input vector must have 2 elements.');end
  9. T=[2.2447e-08 1 16.311742422688 2 4;0.002865160414 0.999995895419 16.358149278102 3 -4;0.145142272809 -0.989410794687 0 -1 -2;8.029448e-06 -0.999999999968 -16.357452075885 5 6;0.002865160414 0.999995895419 16.358149278102 -5 -7;0.002865160414 0.999995895419 16.358149278102 -3 -6];
  10. fF=[0.000875759477659887 0.305656794659812;-2.45423527750168e-06 0.30567112432082;6.88053378066042e-09 0.306527645571793;-1.00610328866168e-09 0.000873305127599464;0.0457142857142857 -5.44477108636138e-17;-3.15706331301852e-20 0.30565439420609;-3.09360366666882e-23 0.30652769247525;2.06793497354346e-25 0.000873298269160258;0.000875759477660942 0.305656841697272;-2.4542356542618e-06 0.305654339664739;0 0;-1.0257619535308e-09 -2.48800844410406e-06;0 0;-2.50216994407249e-06 0.30565439420609;7.01492028208049e-09 0.30652769247525;-1.02575390085844e-09 0.000873298269160258;0.000875759611993472 0.305640111714347;0 0;0 0;-1.04579652716717e-09 7.12863234319177e-09;0 0;-2.50217032819133e-06 0.305637609544866;0 0;-1.04579652710015e-09 -2.4950008942438e-06;0 0;0 0;0 0;-1.06622240733028e-09 0];
  11. fg=[0;0;-8.88178419700125e-16;0;-8.88178419700125e-16;0;-8.88178419700125e-16;0;-7.67262928746959e-07;0.000273786986649149;5;0.0142857120507003;5;0.000273674837632854;-7.67256906009095e-07;1.12191832712938e-07;0.000272892631009825;5;5;0.0142448979655478;5;0.000547461908291247;5;0.0142858264347128;5;5;5;0.0142450145772592];
  12. i=1;nz=4;nx=2;z=NaN(4,1);
  13. while true
  14. h=T(i,1:3)*xh;
  15. if h<=0,i=T(i,4);
  16. else,i=T(i,5);end
  17. if i<0,i=-i;
  18. z=fF((i-1)*nz+1:i*nz,:)*x+fg((i-1)*nz+1:i*nz);
  19. return
  20. elseif i==0,return;end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement