Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. function [Jopt,seq_opt] = optim_recur(xkp,WKp1,seq_par,J_par,A,B,C,N,Joptconnu,seq_opt_connue)
  2.  
  3. if N == 1
  4. Jtot_00=J_par+evaluation(xkp,[0;0],WKp1,A,B,C,1);
  5. Jtot_01=J_par+evaluation(xkp,[0;1],WKp1,A,B,C,1);
  6. Jtot_10=J_par+evaluation(xkp,[1;0],WKp1,A,B,C,1);
  7.  
  8. [Jmin,i_min]=min([Joptconnu,Jtot_00,Jtot_01,Jtot_10]);
  9.  
  10.  
  11. if i_min == 1;
  12. Jopt=Joptconnu;
  13. seq_opt=seq_opt_connue;
  14. elseif i_min == 2
  15. Jopt=Jtot_00;
  16. seq_opt=[seq_par ; [0 ; 0]];
  17. elseif i_min == 3
  18. Jopt=Jtot_01;
  19. seq_opt=[seq_par ; [0 ; 1]];
  20. else
  21. Jopt=Jtot_10;
  22. seq_opt=[seq_par ; [1 ; 0]];
  23. end
  24. else
  25. %
  26. wkp1=WKp1(1:2);
  27. % cas 1 ! uk = [0 ; 0]
  28. uk00=[0;0];
  29. xkp1_00=A*xkp+B*uk00;
  30. ykp1_00=C*xkp1_00;
  31. J_par00=J_par+( ykp1_00- wkp1)'*( ykp1_00- wkp1)+uk00'*uk00;
  32.  
  33. if J_par00>Joptconnu
  34. Jopt00=Joptconnu;
  35. seq_opt00=seq_opt_connue;
  36. else
  37. [Jopt00,seq_opt00]= optim_recur(xkp1_00,WKp1(3:end),[seq_par;uk00],J_par00,A,B,C,N-1,Joptconnu,seq_opt_connue);
  38. end
  39.  
  40. % cas 2 ! uk = [0 ; 1]
  41. uk01=[0;1];
  42. xkp1_01=A*xkp+B*uk01;
  43. ykp1_01=C*xkp1_01;
  44. J_par01=J_par+( ykp1_01- wkp1)'*( ykp1_01- wkp1)+uk01'*uk01;
  45.  
  46. if J_par01>Jopt00
  47. Jopt01=Jopt00;
  48. seq_opt01=seq_opt00;
  49. else
  50. [Jopt01,seq_opt01]= optim_recur(xkp1_01,WKp1(3:end),[seq_par;uk01],J_par01,A,B,C,N-1,Jopt00,seq_opt00);
  51. end
  52.  
  53. % cas 3 ! uk = [1 ; 0]
  54. uk10=[1;0];
  55. xkp1_10=A*xkp+B*uk10;
  56. ykp1_10=C*xkp1_10;
  57. J_par10=J_par+( ykp1_10- wkp1)'*( ykp1_10- wkp1)+uk10'*uk10;
  58.  
  59. if J_par10>Jopt01
  60. Jopt=Jopt01;
  61. seq_opt=seq_opt01;
  62. else
  63. [Jopt,seq_opt]= optim_recur(xkp1_10,WKp1(3:end),[seq_par;uk10],J_par10,A,B,C,N-1,Jopt01,seq_opt01);
  64. end
  65.  
  66. end
  67.  
  68.  
  69.  
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement