clear all;

% constants
f = linspace(1.25,4000,3200);
roh = 2.3e3; % Density                           
E = 2.6e10;  % Young's modulus                         
eta = 0.01;  % loss factor                     
h = 0.10;    % thickness of the plate                        
nue = 0.3;   % Poisson's ratio
lx = 2.8;                                
ly = 2;   
x1 = 1.99;                            
y1 = 1.27;                              
x2 = x1;                              
y2 = y1;                             
w=(2*pi).*f;                        

% max. frequency
fmax=5000;               

%zeros of the gamma-functions
yi = [7.8532 14.13716];
yj = [4.73004 10.9956];

groessef=size(f);
Yf1z1zsummeges = zeros(1,groessef(2));
YMv1x1zsummeges = zeros(1,groessef(2));
YMv1y1zsummeges = zeros(1,groessef(2));
YfW1z1xsummeges = zeros(1,groessef(2));
YM1x1xsummeges  = zeros(1,groessef(2));
YM1y1xsummeges  = zeros(1,groessef(2));
YfW1z1ysummeges = zeros(1,groessef(2));
YM1x1ysummeges  = zeros(1,groessef(2));
YM1y1ysummeges  = zeros(1,groessef(2));

m = 1;
n = 0;
z = 0; %Zähler 
while (1)
    z = z + 1;
    if m == 0
        Gx = 0;
        Hx = 0;
        Jx = 0;
    elseif m == 1
        Gx = 1.506;
        Hx = 1.248;
        Jx = 5.017;
    else
        Gx = m+0.5;
        Hx = (m+0.5)^2*(1-4/((2*m+1)*pi));
        Jx = (m+0.5)^2*(1+12/((2*m+1)*pi));
    end
    if n == 0
        Gy = 0;
        Hy = 0;
        Jy = 0;
    elseif n == 1
        Gy = 1.506;
        Hy = 1.248;
        Jy = 5.017;
    else
        Gy = n+0.5;
        Hy = (n+0.5)^2*(1-4/((2*n+1)*pi));
        Jy = (n+0.5)^2*(1+12/((2*n+1)*pi));
    end
    qmn = sqrt(Gx^4+Gy^4*(lx/ly)^4+2*(lx/ly)^2*(nue*Hx*Hy+(1-nue)*Jx*Jy)); 
    wmnr = sqrt(E*h^2/(12*roh*(1-nue^2)))*(pi/lx)^2*qmn; 
    wmn(z) = wmnr*sqrt(1+j*eta); 
    fmn(z) = wmn(z)/(2*pi);                                     
     
       if m==0
           phix1(z) = 1;
           phix1st(z) = 0; 
           phix2(z) = 1;
           phix2st(z) = 0;
           
       else
           if m/2 == round(m/2); %Abfrage: m gerade Zahl
                ii = m/2;
                if ii > 2;
                   yi(ii) = (4*ii+1)*pi/2;
                end                
                kn = sin(0.5*yi(ii))/sinh(0.5*yi(ii));
                phix1(z) = sqrt(2)*(sin(yi(ii)*(x1/lx-0.5))+kn*sinh(yi(ii)*(x1/lx-0.5))); %phi an der Stelle x1
                phix1st(z) = sqrt(2)*(cos(yi(ii)*(x1/lx-0.5))*yi(ii)/lx+kn*cosh(yi(ii)*(x1/lx-0.5))*yi(ii)/lx);
                phix2(z) = sqrt(2)*(sin(yi(ii)*(x2/lx-0.5))+kn*sinh(yi(ii)*(x2/lx-0.5))); %phi an der Stelle x2
                phix2st(z) = sqrt(2)*(cos(yi(ii)*(x2/lx-0.5))*yi(ii)/lx+kn*cosh(yi(ii)*(x2/lx-0.5))*yi(ii)/lx);
                
           else % n ungerade Zahl
                jj = (m+1)/2;
                if jj > 2;
                   yj(jj) = (4*jj-1)*pi/2;
                end
                kn = -sin(0.5*yj(jj))/sinh(0.5*yj(jj));
                phix1(z) = sqrt(2)*(cos(yj(jj)*(x1/lx-0.5))+kn*cosh(yj(jj)*(x1/lx-0.5))); 
                phix1st(z) = sqrt(2)*(-sin(yj(jj)*(x1/lx-0.5))*yj(jj)/lx+kn*sinh(yj(jj)*(x1/lx-0.5))*yj(jj)/lx);
                phix2(z) = sqrt(2)*(cos(yj(jj)*(x2/lx-0.5))+kn*cosh(yj(jj)*(x2/lx-0.5)));
                phix2st(z) = sqrt(2)*(-sin(yj(jj)*(x2/lx-0.5))*yj(jj)/lx+kn*sinh(yj(jj)*(x2/lx-0.5))*yj(jj)/lx);
                
           end % der if Abfrage n gerade Zahl
        end
        if n == 0
            phiy1(z) = 1;
            phiy1st(z) = 0;
            phiy2(z) = 1;
            phiy2st(z) = 0;
        else
            if n/2 == round(n/2); %Abfrage: n gerade Zahl
                ii = n/2;
                if ii > 2;
                   yi(ii) = (4*ii+1)*pi/2;
                end                
                kn = sin(0.5*yi(ii))/sinh(0.5*yi(ii));
                phiy1(z) = sqrt(2)*(sin(yi(ii)*(y1/ly-0.5))+kn*sinh(yi(ii)*(y1/ly-0.5))); 
                phiy1st(z) = sqrt(2)*(cos(yi(ii)*(y1/ly-0.5))*yi(ii)/ly+kn*cosh(yi(ii)*(y1/ly-0.5))*yi(ii)/ly);
                phiy2(z) = sqrt(2)*(sin(yi(ii)*(y2/ly-0.5))+kn*sinh(yi(ii)*(y2/ly-0.5))); 
                phiy2st(z) = sqrt(2)*(cos(yi(ii)*(y2/ly-0.5))*yi(ii)/ly+kn*cosh(yi(ii)*(y2/ly-0.5))*yi(ii)/ly);
                
            else % m ungerade Zahl
                jj = (n+1)/2;
                if jj > 2;
                   yj(jj) = (4*jj-1)*pi/2;
                end
                kn = -sin(0.5*yj(jj))/sinh(0.5*yj(jj));
                phiy1(z) = sqrt(2)*(cos(yj(jj)*(y1/ly-0.5))+kn*cosh(yj(jj)*(y1/ly-0.5))); 
                phiy1st(z) = sqrt(2)*(-sin(yj(jj)*(y1/ly-0.5))*yj(jj)/ly+kn*sinh(yj(jj)*(y1/ly-0.5))*yj(jj)/ly);
                phiy2(z) = sqrt(2)*(cos(yj(jj)*(y2/ly-0.5))+kn*cosh(yj(jj)*(y2/ly-0.5))); 
                phiy2st(z) = sqrt(2)*(-sin(yj(jj)*(y2/ly-0.5))*yj(jj)/ly+kn*sinh(yj(jj)*(y2/ly-0.5))*yj(jj)/ly);
                
             end % der if Abfrage m gerade Zahl
        end

       psi1(z) = phix1(z)*phiy1(z); % psi an der Stelle 1
       psi2(z) = phix2(z)*phiy2(z); % psi an der Stelle 2
       psiX1(z) = phix1(z)*phiy1st(z); % psi x (m,n) an der Stelle 1 siehe (9.74)
       psiX2(z) = phix2(z)*phiy2st(z); % psi x (m,n) an der Stelle 2
       psiY1(z) = -phix1st(z)*phiy1(z); % psi y (m,n) an der Stelle 1 
       psiY2(z) = -phix2st(z)*phiy2(z); % psi y (m,n) an der Stelle 2 
                   
       Yf1z1zsumme(z,:) = psi1(z).*psi2(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YMv1x1zsumme(z,:) = psi2(z).*psiX1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YMv1y1zsumme(z,:) = psi2(z).*psiY1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YfW1z1xsumme(z,:) = psiX2(z).*psi1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YM1x1xsumme(z,:) = psiX2(z).*psiX1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YM1y1xsumme(z,:) = psiX2(z).*psiY1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YfW1z1ysumme(z,:) = psiY2(z).*psi1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YM1x1ysumme(z,:) = psiY2(z).*psiX1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       YM1y1ysumme(z,:) = psiY2(z).*psiY1(z)./(roh.*h.*lx.*ly.*(wmn(z).^2-w.^2));
       
       Yf1z1zsummeges(1,:) = Yf1z1zsumme(z,:)+Yf1z1zsummeges(1,:);
       YMv1x1zsummeges(1,:) = YMv1x1zsumme(z,:)+YMv1x1zsummeges(1,:);
       YMv1y1zsummeges(1,:) = YMv1y1zsumme(z,:)+YMv1y1zsummeges(1,:);
       YfW1z1xsummeges(1,:) = YfW1z1xsumme(z,:)+YfW1z1xsummeges(1,:);
       YM1x1xsummeges(1,:) = YM1x1xsumme(z,:)+YM1x1xsummeges(1,:);
       YM1y1xsummeges(1,:) = YM1y1xsumme(z,:)+YM1y1xsummeges(1,:) ;
       YfW1z1ysummeges(1,:) = YfW1z1ysumme(z,:)+YfW1z1ysummeges(1,:);
       YM1x1ysummeges(1,:)  = YM1x1ysumme(z,:)+YM1x1ysummeges(1,:) ;
       YM1y1ysummeges(1,:)  = YM1y1ysumme(z,:)+YM1y1ysummeges(1,:);

    if (fmn(z) < fmax)
        m = m + 1;
    elseif (m > 0)
        n = n + 1;
        m = 0;
        z = z - 1;
    else
        break;
    end
end

YfRFree1z1z  = abs(Yf1z1zsummeges(1,:).*j.*w);  %YW,Fz
YMvRFree1x1z = abs(YMv1x1zsummeges(1,:).*j.*w); %YW,Mx
YMvRFree1y1z = abs(YMv1y1zsummeges(1,:).*j.*w); %YW,My
YfWRFree1z1x = abs(YfW1z1xsummeges(1,:).*j.*w); %Y?x,Fz
YMRFree1x1x  = abs(YM1x1xsummeges(1,:).*j.*w);  %Y?x,Mx
YMRFree1y1x  = abs(YM1y1xsummeges(1,:) .*j.*w); %Y?x,My
YfWRFree1z1y = abs(YfW1z1ysummeges(1,:).*j.*w); %Y?y,Fz
YMRFree1x1y  = abs(YM1x1ysummeges(1,:) .*j.*w); %Y?y,Mx
YMRFree1y1y  = abs(YM1y1ysummeges(1,:).*j.*w);  %Y?y,My

loglog(f,YfRFree1z1z)
    grid on;
