0% found this document useful (0 votes)
51 views

5.2 MATLAB Code

This MATLAB code defines system parameters and state space model matrices for a simulink diagram model of a power system. It defines transfer function parameters, control parameters, weighting matrices and performs an LQR controller design to provide inputs to blocks in the simulink diagram model.

Uploaded by

Raju Kuruva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

5.2 MATLAB Code

This MATLAB code defines system parameters and state space model matrices for a simulink diagram model of a power system. It defines transfer function parameters, control parameters, weighting matrices and performs an LQR controller design to provide inputs to blocks in the simulink diagram model.

Uploaded by

Raju Kuruva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

5.

2 MATLAB code
Here, code is written to give inputs separately to the corresponding blocks of simulink diagrams as it is complex to give
the inputs directly.
%%%%%%System Parameters....................
T12 = 0.245;Tg1 = 0.06;Tt1 = 0.32;R1=2.4;Tg2 = 0.08;Tt2 = 0.3;R2=2.5;Kp1 = 102;Tp1 = 20;B1 = 0.425;K1 = .8;Tg3 = 0.06;
Tt3 = 0.03;R3=2.5;Tg4 = 0.07;Tt4 = 0.32;R4=2.7;Kp2 = 102;Tp2 = 25;B2 = 0.396;K2= .8;apf1 = 0.75;apf2 = 0.25;apf3 = 0.5;
apf4 = 0.5;
cpf = [0.5 0.25 0 0.3;
0 0 0 0;
0 0.5 1 0.7;
0.5 0.25 0 0];
%%%Defining State Space model Matrices..........
A11 = [-1 / Tp1 0 Kp1 / Tp1 Kp1 / Tp1 0 0 -Kp1 / Tp1;
0 -1 / Tp2 0 0 Kp2 / Tp2 Kp2 / Tp2 Kp2 / Tp2
0 0 -1 / Tt1 0 0 0 0;
0 0 0 -1 / Tt2 0 0 0;
0 0 0 0 -1 / Tt3 0 0;
0 0 0 0 0 -1 / Tt4 0;
T12 / (2*pi) -T12 / (2*pi) 0 0 0 0 0];
A12 = [0 0 0 0 0 0;
0 0 0 0 0 0;
1 / Tt1 0 0 0 0 0;
0 1 / Tt2 0 0 0 0;
0 0 1 / Tt3 0 0 0;
0 0 0 1 / Tt4 0 0;
0 0 0 0 0 0];
A21 = [-1 / (R1*Tg1*2*pi) 0 0 0 0 0 0;
-1 / (R2*Tg2*2*pi) 0 0 0 0 0 0
0 -1 / (R3*Tg3*2*pi) 0 0 0 0 0;
0 -1 / (R4*Tg4*2*pi) 0 0 0 0 0;
B1 / (2*pi) 0 0 0 0 0 1;
0 B2 / (2*pi) 0 0 0 0 -1];
A22 = [-1 / Tg1 0 0 0 (-K1*apf1) / Tg1 0;
0 -1 / Tg2 0 0 (-K1*apf2) / Tg2 0;
0 0 -1 / Tg3 0 0 (-K1*apf3) / Tg3;
0 0 0 -1 / Tg4 0 (-K1*apf4) / Tg4;
0 0 0 0 0 0;
0 0 0 0 0 0];
Ba = [-Kp1 / Tp1 -Kp1 / Tp1 0 0;
0 0 -Kp2/Tp2 -Kp2 / Tp2;
0 0 0 0;
0 0 0 0;

0 0 0 0;
0 0 0 0;
0 0 0 0];
Bb = [cpf (1,1) / Tg1 cpf (1,2) / Tg1 cpf (1,3) / Tg1 cpf (1,4) / Tg1;
cpf (2,1) / Tg2 cpf (2,2) / Tg2 cpf (2,3) / Tg2 cpf (2,4) / Tg2;
cpf(3,1) / Tg3 cpf (3,2) / Tg3 cpf (3,3) / Tg3 cpf(3,4) / Tg3;
cpf (4,1) / Tg4 cpf (4,2) / Tg4 cpf (4,3) / Tg4 cpf (4,4) / Tg4;
cpf (3,1) + cpf (4,1) cpf (3,2) + cpf (4,2) - (cpf (1,3) + cpf (2,3)) (cpf (1,4) + cpf (2,4));
-(cpf (3,1) + cpf (4,1)) - (cpf (3,2) + cpf (4,2)) cpf (1,3) + cpf (2,3)
cpf (1,4) + cpf (2,4)];
C1 = eye (7, 7);
Q1 = eye (6, 6);
Ra = eye (7,7);
[Ke, Se, Ee] = lqr (A22', A12', Q1, 100*Ra);
L = Ke';
%%%%%Weightage for the State Parameters for control action.......
C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