%%   step 1: create systems P and K
nump=1; denp=[1 2];
P = tf(nump,denp,0,"plant input","plant output");

numk= [1 1]; denk = [1 0];
K = tf(numk, denk,0,"controller input","controller output");

%%   step 2: group P and K together
PK = sysgroup(P,K);

%%   step 3: create a summing junction
%%   Step 3a: duplicate controller input: (input 2 of PK)
PK = sysdup(PK,[],2);

%%   step 3b: scale input 3 by -1
PK = sysscale(PK,[],diag([1, 1, -1]));

%%   step 4: connect outputs to respective inputs
%%Step 4: connect:
%%   y(t) (output 1) to the negative sum junction (input 3)
%%   u(t) (output 2) to plant input (input 1)
%%   and prune extraneous inputs/outputs (retain input 2, output 1)
out_connect = [1, 2]
in_connect = [3, 1]
PK0 = sysconnect(PK,out_connect,in_connect);

%%   step 5: prune the desired i/o connections
PK0 = sysprune(PK0,1,2);
[num,den] = sys2tf(PK0)
[z,p]=sys2zp(PK0)
