%%%% Square matrix summation - works OK 23.05..2014
clear;clc;clf reset;warning off MATLAB:divideByZero;close all
sitil = ['-k  ';'--k ';':k  ';'-.k ';'--ok';':ok ';'-k  ';'--k ';':k  '];linwid = [2 3 3 2 2 2 1 2 2];
T = 1;t = -4:0.02:4;t = t*T;%%% T is assumed to be 1
xt = cos(2*t/T).*exp(-0.5*t.^2/T^2);%xt = 1./(1 + (2*t/T).^2);xt = exp(-0.5*t.^2);
plot(t, xt,sitil(1,:),'LineWidth',linwid(2));
set(gcf,'Color',[1 1 1]);set(gca,'FontSize',16);%axis off
Narr = [1 2 3 4];N = Narr(3);ta = 0.5*T;%ta = 0.5*T;
Xmat = [];
for m = -N:N
    xr = [];
    for n = -N:N
       t = m + n*ta;
       xt = cos(2*t/T).*exp(-0.5*t.^2/T^2);
       xr = [xr xt];
    end
    Xmat = [Xmat;xr];
end
fliplr(Xmat)
cn = inv(Xmat)*[zeros(N,1); 1; zeros(N,1)]
t = -4:1:4;t = t*T;xt = cos(2*t/T).*exp(-0.5*t.^2/T^2);xttum = sum(abs(xt));%xt = 1./(1 + (2*t).^2);
t = -2:1:2;t = t*T;xt = cos(2*t/T).*exp(-0.5*t.^2/T^2);xteq = sum(abs(xt));%xt = 1./(1 + (2*t).^2);
xt = exp(-0.5*t.^2);%xt = 1./(1 + (2*t).^2);%xt = 1./(1 + t.^4);
R = xteq/xttum
% q0 = cn'*xt';