Index: mttroot/mtt/lib/control/PPP/ppp_nlin.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin.m @@ -1,12 +1,12 @@ -function [U, U_all, Error, Y, its] = ppp_nlin (system_name,x_0,par_0,sim,us,w,free,extras) +function [U, U_all, Error, Y, its] = ppp_nlin(system_name,x_0,par_0,sim,us,w,free, Q, extras) - ## usage: [U, U_all, Error, Y,its ] = ppp_nlin (system_name,x_0,par_0,sim,us,w,free,extras) + ## usage: [U, U_all, Error, Y,its ] = ppp_nlin(system_name,x_0,par_0,sim,us,w,free, Q, extras) ## ## - if nargin<8 + if nargin<9 extras.criterion = 1e-8; extras.max_iterations = 10; extras.v = 0.1; extras.verbose = 1; endif @@ -15,19 +15,23 @@ ## Details [n_x,n_y,n_u] = eval(sprintf("%s_def;", system_name)); [n_tau,n_us] = size(us); + if nargin<8 + Q = ones(n_y,1); + endif + ## Checks if (n_us<>n_u) error(sprintf("Inputs (%i) differenct to system inputs (%i)", n_us, n_u)); endif ##Optimise - [par,Par,Error,Y,its] = ppp_optimise(s_system_name,x_0,par_0,sim,us,w,free,extras); + [par,Par,Error,Y,its] = ppp_optimise(s_system_name,x_0,par_0,sim,us,w,free,Q,extras); U = par(free(:,1)); U_all = Par(free(:,1),:); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_nlin_run.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin_run.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin_run.m @@ -1,6 +1,6 @@ -function [y,u,t,p,UU,t_open,t_ppp,t_est,its_ppp,its_est] = ppp_nlin_run (system_name,i_ppp,i_par,A_u,w_s,N_ol,extras) +function [y,u,t,p,UU,t_open,t_ppp,t_est,its_ppp,its_est] = ppp_nlin_run(system_name,i_ppp,i_par,A_u,w_s,N_ol,Q,extras) ## usage: [y,u,t,p,U,t_open,t_ppp,t_est,its_ppp,its_est] = ## ppp_nlin_run (system_name,i_ppp,i_par,A_u,w_s,N_ol[,extras]) ## @@ -29,11 +29,11 @@ ## Globals to pass details to simulation global system_name_sim i_ppp_sim x_0_sim y_sim u_sim A_u_sim simpar_sim ## Defaults - if nargin<7 + if nargin<8 extras.alpha = 0.1; extras.criterion = 1e-5; extras.emulate_timing = 0; extras.max_iterations = 10; extras.simulate = 1; @@ -59,10 +59,14 @@ n_t = round(simpar.last/simpar.dt); # Corresponding length x_0 = eval(sprintf("%s_state(par);", system_name)); x_0_model = x_0; [n_x,n_y,n_u] = eval(sprintf("%s_def;", system_name)); + if nargin<8 + Q = ones(n_y,1); + endif + ## Sensitivity system details -- defines moving horizon simulation simpars = eval(sprintf("%s_simpar;", s_system_name)); pars = eval(sprintf("%s_numpar;", s_system_name)); x_0s = eval(sprintf("%s_state(pars);", s_system_name)); x_0_models = x_0s; @@ -163,11 +167,11 @@ tick = time; [pars,Par,Error,Y,its] = \ ppp_optimise(s_system_name,x_0_models,pars,simpar_est,u_star_t,y_est,i_par,extras); if extras.visual - figure(2); + figure(11); title("Parameter optimisation"); II = [1:length(y_est)]; plot(II,y_est,"*", II,Y); endif est_time = time-tick; @@ -203,13 +207,13 @@ ## Optimize for next interval U_old = U; # Save previous value U = expm(A_u*T_ol)*U; # Initialise from continuation trajectory pars(i_ppp(:,1)) = U; # Put initial value of U into the parameter vector - [U, U_all, Error, Y, its] = ppp_nlin(system_name,x_nexts,pars,simpars,u_star_tau,w_s,i_ppp,extras); + [U, U_all, Error, Y, its] = ppp_nlin(system_name,x_nexts,pars,simpars,u_star_tau,w_s,i_ppp,Q,extras); if extras.visual - figure(3); + figure(12); title("PPP optimisation"); II = [1:length(w_s)]; plot(II,w_s,"*", II,Y); figure(1); endif Index: mttroot/mtt/lib/control/PPP/ppp_optimise.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_optimise.m +++ mttroot/mtt/lib/control/PPP/ppp_optimise.m @@ -1,7 +1,7 @@ function [par,Par,Error,Y,iterations,x] = \ - ppp_optimise(system_name,x_0,par_0,simpar,u,y_0,free,extras); + ppp_optimise(system_name,x_0,par_0,simpar,u,y_0,free,Q,extras); ## Levenberg-Marquardt optimisation for PPP/MTT ## Usage: [par,Par,Error,Y,iterations,x] = ppp_optimise(system_name,x_0,par_0,simpar,u,y_0,free[,extras]); ## system_name String containing system name ## x_0 Initial state ## par_0 Initial parameter vector estimate @@ -12,10 +12,11 @@ ## u System input (column vector, each row is u') ## y_0 Desired model output ## free one row for each adjustable parameter ## first column parameter indices ## second column corresponding sensitivity indices + ## Q vector of positive output weights. ## extras (opt) optimisation parameters ## .criterion convergence criterion ## .max_iterations limit to number of iterations ## .v Initial Levenberg-Marquardt parameter @@ -26,10 +27,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ + ## Revision 1.9 2002/05/08 10:14:21 gawthrop + ## Idetification now OK (Moved data range in ppp_optimise by one sample interval) + ## ## Revision 1.8 2002/04/23 17:50:39 gawthrop ## error --> err to avoid name clash with built in function ## ## Revision 1.7 2001/08/10 16:19:06 gawthrop ## Tidied up the optimisation stuff @@ -61,11 +65,11 @@ ## Extract indices i_t = free(:,1); # Parameters i_s = free(:,2)'; # Sensitivities - if nargin<8 + if nargin<9 extras.criterion = 1e-5; extras.max_iterations = 10; extras.v = 1e-5; extras.verbose = 0; endif @@ -74,10 +78,14 @@ [n_data,n_y] = size(y_0); if n_data1 # Adjust the Levenberg-Marquardt parameter reduction = err_old-err; predicted_reduction = 2*J'*step + step'*JJ*step;