Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [Jopt,seq_opt] = optim_recur(xkp,WKp1,seq_par,J_par,A,B,C,N,Joptconnu,seq_opt_connue)
- if N == 1
- Jtot_00=J_par+evaluation(xkp,[0;0],WKp1,A,B,C,1);
- Jtot_01=J_par+evaluation(xkp,[0;1],WKp1,A,B,C,1);
- Jtot_10=J_par+evaluation(xkp,[1;0],WKp1,A,B,C,1);
- [Jmin,i_min]=min([Joptconnu,Jtot_00,Jtot_01,Jtot_10]);
- if i_min == 1;
- Jopt=Joptconnu;
- seq_opt=seq_opt_connue;
- elseif i_min == 2
- Jopt=Jtot_00;
- seq_opt=[seq_par ; [0 ; 0]];
- elseif i_min == 3
- Jopt=Jtot_01;
- seq_opt=[seq_par ; [0 ; 1]];
- else
- Jopt=Jtot_10;
- seq_opt=[seq_par ; [1 ; 0]];
- end
- else
- %
- wkp1=WKp1(1:2);
- % cas 1 ! uk = [0 ; 0]
- uk00=[0;0];
- xkp1_00=A*xkp+B*uk00;
- ykp1_00=C*xkp1_00;
- J_par00=J_par+( ykp1_00- wkp1)'*( ykp1_00- wkp1)+uk00'*uk00;
- if J_par00>Joptconnu
- Jopt00=Joptconnu;
- seq_opt00=seq_opt_connue;
- else
- [Jopt00,seq_opt00]= optim_recur(xkp1_00,WKp1(3:end),[seq_par;uk00],J_par00,A,B,C,N-1,Joptconnu,seq_opt_connue);
- end
- % cas 2 ! uk = [0 ; 1]
- uk01=[0;1];
- xkp1_01=A*xkp+B*uk01;
- ykp1_01=C*xkp1_01;
- J_par01=J_par+( ykp1_01- wkp1)'*( ykp1_01- wkp1)+uk01'*uk01;
- if J_par01>Jopt00
- Jopt01=Jopt00;
- seq_opt01=seq_opt00;
- else
- [Jopt01,seq_opt01]= optim_recur(xkp1_01,WKp1(3:end),[seq_par;uk01],J_par01,A,B,C,N-1,Jopt00,seq_opt00);
- end
- % cas 3 ! uk = [1 ; 0]
- uk10=[1;0];
- xkp1_10=A*xkp+B*uk10;
- ykp1_10=C*xkp1_10;
- J_par10=J_par+( ykp1_10- wkp1)'*( ykp1_10- wkp1)+uk10'*uk10;
- if J_par10>Jopt01
- Jopt=Jopt01;
- seq_opt=seq_opt01;
- else
- [Jopt,seq_opt]= optim_recur(xkp1_10,WKp1(3:end),[seq_par;uk10],J_par10,A,B,C,N-1,Jopt01,seq_opt01);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement