ATC DAQ.m

From EVOCD
Revision as of 18:01, 8 August 2011 by Haupt (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

back


function Sch1_ATC_DQA
% ATC form with "interior-point" to solve each optimization problem
% with printing procedure
clear; clc; tic;

% Initial Value For Important Parameters%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Landa   = 0     ;   C       = 1     ;
gamma   = 0.25  ;   beta    = 2     ;
Tau     = 0.001  ;   T       = 0.9   ;
UB      = inf   ;
Initial=3; r = Initial; t = Initial; Z(1:8) = Initial;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Initialize parameters to do convergence terminating%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dif1 according to (15) of Tosserams' = inconsistencies difference at two
% consecutive solutions and dif2 objective value differences
h_O         = 1 ;   dif1    = 1 ;
F_O         = 0 ;   dif2    = 1 ;
Itr         = 0 ;   Sheet   = 6 ;
CompCost    = 0 ;   
t_O         = 0 ;   r_O     = 0 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% active-set interior-point
options = optimset('Algorithm','interior-point','display','off',...
        'MaxFunEvals',1e3,'MaxIter',1e3,'MaxFunEvals',1e3);   % Method #1

% while dif1 > Tau || dif2 > Tau/10
while dif1 > Tau
    
    dif3 = 1; dif4 = 1;
    while max(dif3,dif4) > Tau
        
        Itr = Itr + 1
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
        A = [];  b = [];    Aeq = [];  beq = [];
        lb = 0 * ones(1,3);    ub = UB*ones(1,3);

        exitflag = 0;
        while exitflag < 1
            x0 = [Z(3) Z(4) Z(5)];
    %         x0 = lb + rand * (ub-lb);
            [x11,f11,exitflag,output] = ...
                fmincon(@obj1,x0,A,b,Aeq,beq,lb,ub,@const1,options,Landa,C,r);
        end

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        CompCost = CompCost+output.funcCount;
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
        A = [];  b = [];    Aeq = [];  beq = [];
        lb = 0 * ones(1,3);    ub = UB*ones(1,3);

        exitflag = 0;
        while exitflag < 1
    %         x0 = lb + rand * (ub-lb);
            x0 = [Z(8) Z(6) Z(7)];
            [x22,f22,exitflag,output] = ...
                fmincon(@obj2,x0,A,b,Aeq,beq,lb,ub,@const2,options,Landa,C,t);
        end

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        CompCost = CompCost+output.funcCount;
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

        t = t + T * ( x11(3) - t );
        dif3 = abs( x11(3) - t_O)
        t_O = x11(3);    

        Z(3) = x11(1); Z(4) = x11(2); Z(5) = t;

        r = r + T * ( x22(1) - r );
        dif4 = abs( x22(1) - r_O);
        r_O = x22(1);

        Z(6) = x22(2); Z(7) = x22(3); Z(8) = x22(1);

        Z(1) = sqrt(Z(3)^2 + Z(4)^-2 + Z(5)^2);
        Z(2) = sqrt(Z(5)^2 + Z(6)^2 + Z(7)^2);
        F_N = Z(1)^2 + Z(2)^2;
    
    end
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    h_N = ( t - r );
    Landa = Landa + 2 * C^2 * h_N;
    
    if ( abs(h_N) > gamma*abs(h_O) )
        C = beta * C;
    else
        C = C;
    end
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
    
    dif1 = abs (h_N - h_O);
    dif2 = abs (F_N - F_O);
    h_O = h_N;  F_O = F_N;
    
    error = sqrt ((Z(1)-2.15)^2+(Z(2)-2.06)^2+(Z(3)-1.32)^2+(Z(4)-0.76)^2 ...
        + (Z(5)-1.07)^2+(Z(6)-1)^2+(Z(7)-1.47)^2);
    
    errorP = 100 * sqrt ( ((Z(1)-2.15)/2.15)^2 +((Z(2)-2.06)/2.06)^2+((Z(3)-1.32)/1.32)^2+...
        ((Z(4)-0.76)/0.76)^2+((Z(5)-1.07)/1.07)^2+((Z(6)-1)/1)^2+((Z(7)-1.47)/1.47)^2);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % PRINT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    Ex(Itr,1:8)=Z;
    Ex(Itr,9  )=F_N;
    Ex(Itr,10 )=dif1;
    Ex(Itr,11 )=dif2;
    Ex(Itr,12 )=beta;
    Ex(Itr,13 )=Tau;
    Ex(Itr,14 )=Initial;
    Ex(Itr,15 )=Itr;
    Ex(Itr,16 )=CompCost;
    Ex(Itr,17 )=error;
    
end

Z
CompCost
error
errorP
% xlswrite('DQA.xlsx',Ex,Sheet)
toc;
    

function f = obj1(z,Landa,C,r)
z3 = z(1); z4 = z(2); t = z(3);

f = (z3^2 + z4^-2 + t^2) ...
    + Landa * ( t - r ) + C^2 * ( t - r )^2;

function [c,ceq] = const1(z,Landa,C,r)
z3 = z(1); z4 = z(2); t = z(3);

% Inequality constraints
c(1) = (z3^-2 + z4^2)*t^-2-1;

% Equality Constraints
ceq = [];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function f = obj2(z,Landa,C,t)
r = z(1); z6 = z(2); z7 = z(3);

f = (r^2 + z6^2 + z7^2) ...
    + Landa * ( t - r ) + C^2 * ( t - r )^2;

function [c,ceq] = const2(z,Landa,C,t)
r = z(1); z6 = z(2); z7 = z(3);

% Inequality constraints
c(1) = (r^2 + z6^-2)*z7^-2-1;

% Equality Constraints
ceq = [];
Personal tools
Namespaces

Variants
Actions
home
Materials
Material Models
Design
Resources
Projects
Education
Toolbox