clear all
clc

P_feed=1.31e5
alpha_L_feed=0.5;
gen_data
OPz=35;
load Stationary
load data



index=find(abs(z-OPz)==min(abs(z-OPz))); %finner indeks hvor z er tilnaermet lik operasjonell pkt.
u=[z(index);P_feed;alpha_L_feed];
%u=[z(index);mG_in;mL_in;50]; % modellen er for konstant massestrom inn

global data rho_mix                     ??????????????
[A,B,C,D,E,F,ys]=linearize(@slug_3D_lin,[],xs(1:3,index),[],u(1),u(2:3)); % forstyrrelser i mG_in, mL_in og P0
%transfer funksjon for:
%  Y     output( P1,P2,p.T,W, Q)
% ---    
%  z    ventilaapning
G=ss(A,B,C,D);
G_tf=tf(G);
%transfer funksjon for:
%  Y     output( P1,P2,p.T,W, Q)
% ---    
%  d     forstyrrelse (mG_in, mL_in)
Gd=ss(A,E,C,F);
Gd=Gd(:,1:2);
Gd_tf=tf(Gd);
%transfer funksjon for:
%  P2    output
% ---    
%  z    ventilaapning
GP1=G_tf(1);
GP1=zpk(GP1);
GP2=G_tf(2);
GP2=zpk(GP2);
GpT=G_tf(3);
GpT=zpk(GpT);
GW=G_tf(4);
GW=zpk(GW);
GQ=G_tf(5);
GQ=zpk(GQ);
% poler_GP1=pole(GP1)
% nuller_GP1=zero(GP1)
% 
% poler_GP2=pole(GP2)
% nuller_GP2=zero(GP2)
% 
% poler_GpT=pole(GpT)
% nuller_GpT=zero(GpT)
% 
% poler_GW=pole(GW)
% nuller_GW=zero(GW)
% 
%poler_GQ=pole(GQ)
% nuller_GQ=zero(GQ)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Kaskade struktur
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
G1=GP2;
G2=GQ;
Kc1=-0.115;tau1=700;
Kc2=-0.001;tau2=1200;

if tau1==0
    K1=Kc1;
else
K1=Kc1*tf([tau1 1],[tau1 0]);
end

if Kc2==0
    K2=Kc2;
else
K2=Kc2*tf([tau2 1],[tau2 0]);
end
L1=K1*G1;
L2=K2*G2;
S1=1/(1+L1);
T1=L1/(1+L1);
S2=1/(1+L2);
T2=L2/(1+L2);
G=G1*S2*K2;

L=K1*G;
S=1/(1+L);
T=L/(1+L);



