% This program calculates the numerical values of q1 of ECE 633 mt 2015
clear;clc;
syms A T s1 s2 s3 s4 s5 s6 s7 s8 n1 n2 Fi1 Fi2 r r1 r2 CT real
s1 = [A*sqrt(0.5*T) -A*sqrt(0.5*T)];s2 = [A*sqrt(0.5*T) A*sqrt(0.5*T)]; 
s3 = [-A*sqrt(0.5*T) A*sqrt(0.5*T)];s4 = [-A*sqrt(0.5*T) -A*sqrt(0.5*T)];
s5 = [1.2*A*sqrt(T) 0];s6 = [0 1.2*A*sqrt(T)]; 
s7 = [-1.2*A*sqrt(T) 0];s8 = [0 -1.2*A*sqrt(T)];
Fi1 = [sqrt(2)/sqrt(T) 0];Fi2 = [0 sqrt(2)/sqrt(T)];
s1t = [A*sqrt(2) 0];s2t = [A/sqrt(2) A/sqrt(T)];
r1 = A*sqrt(0.5*T) + n1;r2 = -A*sqrt(0.5*T) + n2;Ep1 = A^2*T;
% r21 = sum(s2t.*Fi1) + n1;r22 = sum(s2t.*Fi2) + n2;r2 = [r21;r22]
r = [A*sqrt(0.5*T) + n1;-A*sqrt(0.5*T) + n2];
C11 = 2*s1*r - sum(s1.^2);C11 = simplify(C11);
C12 = 2*s2*r - sum(s2.^2);C12 = simplify(C12);
C13 = 2*s3*r - sum(s3.^2);C13 = simplify(C13);
C14 = 2*s4*r - sum(s4.^2);C14 = simplify(C14);
C15 = 2*s5*r - sum(s5.^2);C15 = simplify(C15);
C16 = 2*s6*r - sum(s6.^2);C16 = simplify(C16);
C17 = 2*s7*r - sum(s7.^2);C17 = simplify(C17);
C18 = 2*s8*r - sum(s8.^2);C18 = simplify(C18);
CT = [C11;C12;C13;C14;C15;C16;C17;C18];
%pretty(CT)
%%%% In terms of r1 and r2 and Ep1
syms r1 r2 Ep1 Ep5 real
s1 = [sqrt(0.5*Ep1) -sqrt(0.5*Ep1)];s2 = [sqrt(0.5*Ep1) sqrt(0.5*Ep1)];s3 = [-sqrt(0.5*Ep1) sqrt(0.5*Ep1)];s4 = [-sqrt(0.5*Ep1) -sqrt(0.5*Ep1)];
s5 = [1.2*sqrt(Ep1) 0];s6 = [0 1.2*sqrt(Ep1)];s7 = [-1.2*sqrt(Ep1) 0];s8 = [0 -1.2*sqrt(Ep1)];Ep5 = 1.44*Ep1;
C11 = 2*s1*[r1;r2] - Ep1;C11 = simplify(C11);
C12 = 2*s2*[r1;r2] - Ep1;C12 = simplify(C12);
C13 = 2*s3*[r1;r2] - Ep1;C13 = simplify(C13);
C14 = 2*s4*[r1;r2] - Ep1;C14 = simplify(C14);
C15 = 2*s5*[r1;r2] - Ep5;C15 = simplify(C15);
C16 = 2*s6*[r1;r2] - Ep5;C16 = simplify(C16);
C17 = 2*s7*[r1;r2] - Ep5;C17 = simplify(C17);
C18 = 2*s8*[r1;r2] - Ep5;C18 = simplify(C18);
% 
[simplify(C11 - C12);simplify(C11 - C13);simplify(C11 - C14)
 simplify(C11 - C15);simplify(C11 - C16);simplify(C11 - C17);simplify(C11 - C18)]
%dif15 = -25/A/sqrt(T)*simplify(C11 - C15)
%diffg = dif15 - 1*((60 - 25*sqrt(2))*n1 + 25*sqrt(2)*n2 - (61 - 30*sqrt(2))*A*sqrt(T));

%diffg = simple(diffg)
% othr = 2*r2 - 2*(1 - 30*sqrt(2)/25)*r1 - 2*11*sqrt(Ep1)/25/sqrt(2);
% n1 = 3.1;n2 = 4.05;A = 1;T = 0.5;
% eval(dif15)
% eval(othr)*25/sqrt(2)

% dif16 = 25/2/A/sqrt(T)*simplify(C11 - C16)
% diffg = dif16 + 2*((60/2 + 25/sqrt(2))*n2 - 25/sqrt(2)*n1 - (61/sqrt(2) + 30)*A*sqrt(T/2));
% diffg = simplify(diffg);
% % n1 = 0.1;n2 = 4.05;A = 3.06;T = 0.5;
% % eval(diffg)
% 
% othr = r2 - (25/(30*sqrt(2) + 25))*r1 - 11/(30*sqrt(2) + 25)*sqrt(Ep1);
% n1 = 3.1;n2 = 4.05;A = 1;T = 0.5;
% eval(dif16)
% eval(othr)*(30 + 25/sqrt(2))