close all 
clear all
clc
disp('------====== MODAL ANALYSIS ======------')
disp(' ')
disp(' ')
disp(' Autor: Ales Kratochvil ')
disp(' ales.kratochvil@cvut.cz')
disp(' Institution: Czech Technical University in Prague')
disp(' 2022')
%
disp(' ')
%
NORMALIZACE=1;       % 0=BEZ NORMALIZACE / 1=MAX /  2=MASS  v DP pouzita "MAX"
VYBER_MOD=1;         % Cislo modu od 1 do 18 pro samostatnou vizualizaci
SKUPINA_GRAFU=1;     % 0=ZADNY / 1 = Mody 1-9 / 2 = Mody 10-18 / 3 = Mody 1-18
OCASNI_PLOCHY=2;     % 1=Klasicke usporadani   2= T-koncepce
%
nazev='Modal Analysis';
%                   ISO-zadni   ISO-pradni    Z BOKU   ZE ZADU    ZE SHORA       
x_view = 1;   %        1           -1           1          0          0
y_view = 1;   %        1           -1           0          1          0
z_view = 0.7;   %     0.7          1           0          0          1
%
%
%**** VOP *****     **** SOP *****      **** TRUP ****
EIx_1=2.48E+04;      EIx_2=5.6E+03;      EIx_3=8.895E+5;   %ohybova tuhost
GJp_1=4.65E+03;      GJp_2=5.04E+04;     GJp_3=1.170E+05;   %torzni tuhost
EIy_1=1.0E+06;       EIy_2=1.0E+06;      EIy_3=2.952E+05;   %predozadni tuhost  
EA_vop=1.0E+09;      EA_sop=1.0E+09;     EA_tr=1.0E+09;  %ABS.T.. 
%
ZADANI_vop=[                                                                                                                % *)
%Nod_ID    z      dL     x_p        c      xe     xk       m          S_eo         J_eo       S_k         J_k     delta_J  Elm_ID  Nd@A  Nd@B   OHYB   TORZE    PRED. k_delta   k_delta_T 
1       -1.250	0.156	0.276	0.115	-0.057	-0.038	2.990000	0.675823	0.239818	0.008200	0.023000	0.0     1       1     2     1.00	1.00	1.00	0.0      480
2       -1.094	0.157	0.143	0.209	-0.104	0.049	2.990000	0.535293	0.182896	0.008200	0.023000	0.0     2       2	  3     1.00	1.00	1.00	0.0      480   
3       -0.937	0.156	0.105	0.239	-0.119	0.071	2.990000	0.490443	0.167510	0.008200	0.023000	0.0     3       3	  4     1.00	1.00	1.00	0.0      480
4       -0.781	0.156	0.071	0.267	-0.133	0.092	2.990000	0.448583	0.154364	0.008200	0.023000	0.0     4       4	  5     1.00	1.00	1.00	0.0      480
5       -0.625	0.156	0.057	0.282	-0.141	0.098	2.990000	0.426158	0.147803	0.008200	0.023000	0.0     5       5	  6     1.00	1.00	1.00 	0.0      480
6       -0.469	0.156	0.043	0.296	-0.148	0.104	2.990000	0.404480	0.141781	0.008200	0.023000	0.0     6       6	  7     1.00	1.00	1.00	0.0      480
7       -0.313	0.156	0.029	0.311	-0.155	0.112	2.990000	0.382803	0.136073	0.008200	0.023000	0.0     7       7	  8     1.00	1.00	1.00	0.0      480
8       -0.157	0.157	0.014	0.325	-0.163	0.118	2.990000	0.361125	0.130680	0.008200	0.023000	0.0     8       8	  9     1.00	1.00	1.00	0.0      480
9       0.000	0.157	0.000	0.340	-0.170	0.125	2.990000	0.338700	0.125431	0.008200	0.023000    0.2530	9       9	  10	1.00	1.00	1.00	98.4     480
10      0.157	0.156	0.014	0.325	-0.163	0.118	2.990000	0.361125	0.130680	0.008200	0.023000	0.0     10      10	  11	1.00	1.00	1.00	0.0      480
11      0.313	0.156	0.029	0.311	-0.155	0.112	2.990000	0.382803	0.136073	0.008200	0.023000	0.0     11      11	  12	1.00	1.00	1.00  	0.0      480
12      0.469	0.156	0.043	0.296	-0.148	0.104	2.990000	0.404480	0.141781	0.008200	0.023000	0.0     12      12	  13	1.00	1.00	1.00 	0.0      480
13      0.625	0.156	0.057	0.282	-0.141	0.098	2.990000	0.426158	0.147803	0.008200	0.023000	0.0     13      13	  14	1.00	1.00	1.00 	0.0      480
14      0.781	0.156	0.071	0.267	-0.133	0.092	2.990000	0.448583	0.154364	0.008200	0.023000	0.0     14      14	  15	1.00	1.00	1.00    0.0      480
15      0.937	0.157	0.105	0.239	-0.119	0.071	2.990000	0.490443	0.167510	0.008200	0.023000	0.0     15      15	  16	1.00	1.00	1.00    0.0      480
16      1.094	0.156	0.143	0.209	-0.104	0.049	2.990000	0.535293	0.182896	0.008200	0.023000	0.0     16      16	  17	1.00	1.00	1.00    0.0      480
17      1.250	0.156	0.276	0.115	-0.057	-0.038	2.990000	0.675823	0.239818	0.008200	0.023000	0.0     0       0	  0 	0.00	0.00	0.00	0.0      0
];
%
%
ZADANI_sop=[    
%Nod_ID   y       dL      x_p      c      xe      xk        m       S_eo           J_eo        S_k         J_k     delta_J  Elm_ID  Nd@A   Nd@B  OHYB   TORZE  PRED.  k_delta  k_delta_T                    
9       -1.054	0.072	0.503	0.225	-0.112	0.225	4.971720	0.885104	0.386070	0.000000	0.000000	0       17      9	    18   1.00	1.00	1.00	0       0
18  	-0.982	0.110	0.469	0.374	-0.187	0.090	5.224372	0.467604	0.323455	0.175000	0.057045	0       18      18      19	 1.00	1.00	1.00	0       100000
19      -0.872	0.110	0.416	0.396	-0.198	0.088	5.748953	0.530520	0.313178	0.175000	0.057045	0       19      19      20	 2.00	1.00	1.00	0       100000
20      -0.762	0.110	0.364	0.418	-0.209	0.087	7.509900	0.950586	0.595280	0.175000	0.057045	0       20      20      21	 10.0	1.00	1.00	0       100000
21      -0.652	0.110	0.311	0.440	-0.220	0.086	6.474565	1.055731	0.726005	0.175000	0.057045	0       21      21      22	 20.0	1.00	1.00	0       100000
22      -0.542	0.110	0.259	0.462	-0.231	0.085	6.679150	1.169516	0.761727	0.175000	0.057045	0       22      22      23	 20.0	1.00	1.00	0       100000
23      -0.432	0.110	0.206	0.485	-0.242	0.084	6.699475	1.277787	0.785818	0.175000	0.057045	0       23      23      24	 20.0	1.00	1.00	0       100000
24      -0.322	0.110	0.154	0.507	-0.253	0.084	6.886465	1.400588	0.815775	0.175000	0.057045	0       24      24      25	 10.4	1.00	1.00	0       100000
25      -0.212	0.110	0.101	0.529	-0.264	0.083	23.997350	-0.431260	1.424372	0.175000	0.057045	0       25      25      26	 11.2	1.00	1.00	0       100000
26      -0.102	0.102	0.049	0.551	-0.275	0.082	38.970880	0.303380	1.643110	0.175000	0.057045	0       26      26      27	 10.2	1.00	1.00	0       100000
27      0.000	0.153	0.000	0.571	-0.286	0.080	23.460293	3.871712	2.201518	0.175000	0.057045	0       27      27      28	 11.2	1.00	1.00	0       100000
28      0.153	0.153   -.073	0.600	-0.300	0.081	15.556100	4.895570	2.434609	0.175000	0.057045	0.040	0       0	    0	 0.00	0.00	0.00	358     0
];
%
%
ZADANI_tr=[
%Nod_ID   x      dL     x_p      c     xe       m       S_eo    J_eo        Elm_ID  Nd@A  Nd@B   OHYB    TORZE   PRED. 
27      0       0.171	0.029	0.113	0	6.6094      0       0.125475328	28      27      29   1.00	1.00	1.00
29      -0.171	0.200	0.029	0.113	0	9.1866      0       0.174401859	29      29      30	 1.00	1.00	1.00
30      -0.371	0.200	0.022	0.112	0	7.4946      0       0.139762111	30      30      31	 1.00	1.25	1.00
31      -0.571	0.200	0.013	0.116	0	7.251       0       0.146362258	31      31      32	 1.00	2.50	1.00
32      -0.771	0.200	0.004	0.121	0	5.272       0       0.114832671	32      32      33	 1.00	2.50	1.00
33      -0.971	0.200	-.006	0.125	0	4.674       0       0.109553906	33      33      34	 1.00	2.50	1.00
34      -1.171	0.200	-.015	0.129	0	4.779       0       0.119300993	34      34      35	 1.00	2.50	1.00
35      -1.371	0.200	-.023	0.133	0	4.885       0       0.128630255	35      35      36	 1.00	2.50	1.00
36      -1.571	0.200	-.034	0.139	0	4.981       0       0.143314426	36      36      37	 1.00	2.50	1.00
37      -1.771	0.200	-.047	0.147	0	5.977       0       0.193725765	37      37      38	 1.00	2.50	1.00
38      -1.971	0.200	-.059	0.162	0	5.368       0       0.211332434	38      38      39	 1.00	2.50	1.00
39      -2.171	0.200	-.071	0.184	0	6.061       0       0.307801824	39      39      40	 1.00	2.50	1.00
40      -2.371	0.200	-.080	0.216	0	5.832       0       0.406287171	40      40      41	 1.00	2.50	1.00
41      -2.571	0.200	-.089	0.252	0	7.241       0       0.687023801	41      41      42	 1.00	2.50	1.00
42      -2.771	0.200	-.100	0.297	0	7.241       0       0.958095285	0       0       0	 0.00	0.00	0.00
];
%
%
%
%
%--------------------------------------------------------------------------
%                   Extrahovani zadani a vypocet konstant
%--------------------------------------------------------------------------
%       VOP        %
Nod_ID_vop=ZADANI_vop(:,1)';
z_vop=ZADANI_vop(:,2)';
dL_vop=ZADANI_vop(:,3)';
x_p_vop=ZADANI_vop(:,4)';
c_vop=ZADANI_vop(:,5)';
xe_vop=ZADANI_vop(:,6)';
xk_vop=ZADANI_vop(:,7)';
m_vop=ZADANI_vop(:,8)';
S_eo_vop=ZADANI_vop(:,9)';
J_eo_vop=ZADANI_vop(:,10)';
S_k_vop=ZADANI_vop(:,11)';
J_k_vop=ZADANI_vop(:,12)'+ZADANI_vop(:,13)'*1;
Elm_vop=ZADANI_vop(:,14)';
NdA_vop=ZADANI_vop(:,15)';
NdB_vop=ZADANI_vop(:,16)';
EIx_vop=ZADANI_vop(:,17)'*EIx_1; %OHYB
GJp_vop=ZADANI_vop(:,18)'*GJp_1; %TORZE
EIy_vop=ZADANI_vop(:,19)'*EIy_1; %PRED.
k_delta_vop=ZADANI_vop(:,20)';
k_delta_T_vop=ZADANI_vop(:,21)';
%
pocet_nodu_vop=numel(Nod_ID_vop);
pocet_elem_vop=pocet_nodu_vop-1;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       SOP           %
Nod_ID_sop=ZADANI_sop(:,1)';
y_sop=ZADANI_sop(:,2)';
dL_sop=ZADANI_sop(:,3)';
x_p_sop=ZADANI_sop(:,4)';
c_sop=ZADANI_sop(:,5)';
xe_sop=ZADANI_sop(:,6)';
xk_sop=ZADANI_sop(:,7)';
m_sop=ZADANI_sop(:,8)';
S_eo_sop=ZADANI_sop(:,9)';
J_eo_sop=ZADANI_sop(:,10)';
S_k_sop=ZADANI_sop(:,11)';
J_k_sop=ZADANI_sop(:,12)'+ZADANI_sop(:,13)';
Elm_sop=ZADANI_sop(:,14)'; 
NdA_sop=ZADANI_sop(:,15)';
NdB_sop=ZADANI_sop(:,16)';
EIx_sop=ZADANI_sop(:,17)'*EIx_2; %OHYB
GJp_sop=ZADANI_sop(:,18)'*GJp_2; %TORZE
EIy_sop=ZADANI_sop(:,19)'*EIy_2; %PRED.
k_delta_sop=ZADANI_sop(:,20)';
k_delta_T_sop=ZADANI_sop(:,21)';
%
pocet_nodu_sop=numel(Nod_ID_sop);
pocet_elem_sop=pocet_nodu_sop-1;
%
% Transformacni matice pro tuhosti R_sop a hmotnosti R_sop2
r_sop=[1 0 0;0 0 1; 0 -1 0];
R_sop=[r_sop zeros(3) zeros(3) zeros(3) zeros(3) zeros(3);
    zeros(3) r_sop zeros(3) zeros(3) zeros(3) zeros(3);
    zeros(3) zeros(3) r_sop zeros(3) zeros(3) zeros(3);
    zeros(3) zeros(3) zeros(3) r_sop zeros(3) zeros(3);
    zeros(3) zeros(3) zeros(3) zeros(3) r_sop zeros(3);
    zeros(3) zeros(3) zeros(3) zeros(3) zeros(3) r_sop];
R_sop2=[r_sop zeros(3) zeros(3); zeros(3) r_sop zeros(3); zeros(3) zeros(3) r_sop];
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       TRUP        %
Nod_ID_tr=ZADANI_tr(:,1)';
x_tr=ZADANI_tr(:,2)';
dL_tr=ZADANI_tr(:,3)';
x_p_tr=ZADANI_tr(:,4)';
c_tr=ZADANI_tr(:,5)';
xe_tr=ZADANI_tr(:,6)';
m_tr=ZADANI_tr(:,7)';
S_eo_tr=ZADANI_tr(:,8)';
J_eo_tr=ZADANI_tr(:,9)';
Elm_tr=ZADANI_tr(:,10)';   
NdA_tr=ZADANI_tr(:,11)';
NdB_tr=ZADANI_tr(:,12)';
EIx_tr=ZADANI_tr(:,13)'*EIx_3; %OHYB
GJp_tr=ZADANI_tr(:,14)'*GJp_3; %TORZE
EIy_tr=ZADANI_tr(:,15)'*EIy_3; %PRED.
%
pocet_nodu_tr=numel(Nod_ID_tr);
pocet_elem_tr=pocet_nodu_tr-1;
%
S_k_tr=zeros(1,pocet_nodu_tr);         % Absence prvku v zadani 
J_k_tr=zeros(1,pocet_nodu_tr);         % Absence prvku v zadani 
k_delta_tr=zeros(1,pocet_nodu_tr);     % Absence prvku v zadani 
xk_tr=zeros(1,pocet_nodu_tr);          % Absence prvku v zadani 
%
% Transformacni matice pro tuhosti R_tr a hmotnosti R_tr2
r_tr=[0 0 1;0 1 0; -1 0 0];
R_tr=[r_tr zeros(3) zeros(3) zeros(3) zeros(3) zeros(3);
    zeros(3) r_tr zeros(3) zeros(3) zeros(3) zeros(3);
    zeros(3) zeros(3) r_tr zeros(3) zeros(3) zeros(3);
    zeros(3) zeros(3) zeros(3) r_tr zeros(3) zeros(3);
    zeros(3) zeros(3) zeros(3) zeros(3) r_tr zeros(3);
    zeros(3) zeros(3) zeros(3) zeros(3) zeros(3) r_tr];
R_tr2=[r_tr zeros(3) zeros(3); zeros(3) r_tr zeros(3); zeros(3) zeros(3) r_tr];
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pocet_nodu=numel(c_vop)+numel(c_sop)+numel(c_tr)-2;
%
%  Nd@id DOF;
OP=[pocet_nodu 1;
    pocet_nodu 2;
    pocet_nodu 3;
    pocet_nodu 4;
    pocet_nodu 5;
    pocet_nodu 6];
%
% VIZUALIZCE OP
if OCASNI_PLOCHY==2  % tj. T-OP
VT_VOP_Y=min(y_sop);%   % Vizualizacni translace VOP v ohybovem smeru
n=find(y_sop==VT_VOP_Y);
VT_VOP_X=x_p_sop(1,n);  % Vizualizacni translace VOP v predozadnim smeru
else
VT_VOP_X=0;
VT_VOP_Y=max(y_sop);
end
%
%
%--------------------------------------------------------------------------
%              SKLADANI GLOBALNI MATICE TUHOSTI --- VOP
%--------------------------------------------------------------------------
%
Kgl=zeros(9*pocet_nodu);
%
%KODOVA CISLA
for n=1:pocet_elem_vop
CODE_VOP(n,:)=[(NdA_vop(n)*9)-8:(NdA_vop(n)*9),(NdB_vop(n)*9)-8:(NdB_vop(n)*9)];
end
%
% SKLADANI DO GLL MATICE TUHOSTI
for n=1:pocet_elem_vop
    kc=CODE_VOP(n,:);       % kodova cisla n-teho elementu
    %
    A1=EA_vop/dL_vop(n);
    A2=12*EIy_vop(n)/dL_vop(n)^3;
    A3=12*EIx_vop(n)/dL_vop(n)^3;
    A4=6*EIy_vop(n)/dL_vop(n)^2;
    A5=6*EIx_vop(n)/dL_vop(n)^2;
    A6=GJp_vop(n)/dL_vop(n);
    A7=4*EIy_vop(n)/dL_vop(n);
    A8=4*EIx_vop(n)/dL_vop(n);
    A9=k_delta_T_vop(n)/dL_vop(n);
    %
    Kelm=[A2  0   0   0    A4   0   0   0    0    -A2 0   0   0    A4   0   0   0    0;
          0   A3  0   -A5  0    0   0   0    0    0   -A3 0   -A5  0    0   0   0    0;
          0   0   A1  0    0    0   0   0    0    0   0   -A1 0    0    0   0   0    0;
          0   -A5 0   A8   0    0   0   0    0    0   A5  0   A8/2 0    0   0   0    0;
          A4  0   0   0    A7   0   0   0    0    -A4 0   0   0    A7/2 0   0   0    0; 
          0   0   0   0    0    A6  0   0    0    0   0   0   0    0    -A6 0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    A9   0   0   0   0    0    0   0   0    -A9;
          -A2 0   0   0    -A4  0   0   0    0    A2  0   0   0    -A4  0   0   0    0;
          0   -A3 0   A5   0    0   0   0    0    0   A3  0   A5   0    0   0   0    0;
          0   0   -A1 0    0    0   0   0    0    0   0   A1  0    0    0   0   0    0;
          0   -A5 0   A8/2 0    0   0   0    0    0   A5  0   A8   0    0   0   0    0;
          A4  0   0   0    A7/2 0   0   0    0    -A4 0   0   0    A7   0   0   0    0; 
          0   0   0   0    0    -A6  0  0    0    0   0   0   0    0    A6  0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    -A9  0   0   0   0    0    0   0   0    A9];
    %
    Kgl(kc,kc)=Kgl(kc,kc)+Kelm;   % nacti lokalni matici k-teho elementu do GLL matice
end
%
%--------------------------------------------------------------------------
%              SKLADANI GLOBALNI MATICE TUHOSTI --- SOP
%--------------------------------------------------------------------------
%
%KODOVA CISLA
for n=1:pocet_elem_sop
CODE_SOP(n,:)=[(NdA_sop(n)*9)-8:(NdA_sop(n)*9),(NdB_sop(n)*9)-8:(NdB_sop(n)*9)];
end
%
%
%
% SKLADANI DO GLL MATICE TUHOSTI
for n=1:pocet_elem_sop
    kc=CODE_SOP(n,:);       % kodova cisla n-teho elementu
    %
    A1=EA_sop/dL_sop(n);
    A2=12*EIy_sop(n)/dL_sop(n)^3;
    A3=12*EIx_sop(n)/dL_sop(n)^3;
    A4=6*EIy_sop(n)/dL_sop(n)^2;
    A5=6*EIx_sop(n)/dL_sop(n)^2;
    A6=GJp_sop(n)/dL_sop(n);
    A7=4*EIy_sop(n)/dL_sop(n);
    A8=4*EIx_sop(n)/dL_sop(n);
    A9=k_delta_T_sop(n)/dL_sop(n);
    %
    Kelm=[A2  0   0   0    A4   0   0   0    0    -A2 0   0   0    A4   0   0   0    0;
          0   A3  0   -A5  0    0   0   0    0    0   -A3 0   -A5  0    0   0   0    0;
          0   0   A1  0    0    0   0   0    0    0   0   -A1 0    0    0   0   0    0;
          0   -A5 0   A8   0    0   0   0    0    0   A5  0   A8/2 0    0   0   0    0;
          A4  0   0   0    A7   0   0   0    0    -A4 0   0   0    A7/2 0   0   0    0; 
          0   0   0   0    0    A6  0   0    0    0   0   0   0    0    -A6 0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    A9   0   0   0   0    0    0   0   0    -A9;
          -A2 0   0   0    -A4  0   0   0    0    A2  0   0   0    -A4  0   0   0    0;
          0   -A3 0   A5   0    0   0   0    0    0   A3  0   A5   0    0   0   0    0;
          0   0   -A1 0    0    0   0   0    0    0   0   A1  0    0    0   0   0    0;
          0   -A5 0   A8/2 0    0   0   0    0    0   A5  0   A8   0    0   0   0    0;
          A4  0   0   0    A7/2 0   0   0    0    -A4 0   0   0    A7   0   0   0    0; 
          0   0   0   0    0    -A6  0  0    0    0   0   0   0    0    A6  0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    -A9  0   0   0   0    0    0   0   0    A9];
    %
    % Transformace
    Kelm_T=R_sop'*Kelm*R_sop;
    Kgl(kc,kc)=Kgl(kc,kc)+Kelm_T;   % nacti lokalni matici k-teho elementu do GLL matice
end
%
%--------------------------------------------------------------------------
%              SKLADANI GLOBALNI MATICE TUHOSTI --- TRUP
%--------------------------------------------------------------------------
%
%KODOVA CISLA
for n=1:pocet_elem_tr
CODE_TR(n,:)=[(NdA_tr(n)*9)-8:(NdA_tr(n)*9),(NdB_tr(n)*9)-8:(NdB_tr(n)*9)];
end
%
%
%
%
% SKLADANI DO GLL MATICE TUHOSTI
for n=1:pocet_elem_tr
    kc=CODE_TR(n,:);       % kodova cisla n-teho elementu
    %
    A1=EA_tr/dL_tr(n);
    A2=12*EIy_tr(n)/dL_tr(n)^3;
    A3=12*EIx_tr(n)/dL_tr(n)^3;
    A4=6*EIy_tr(n)/dL_tr(n)^2;
    A5=6*EIx_tr(n)/dL_tr(n)^2;
    A6=GJp_tr(n)/dL_tr(n);
    A7=4*EIy_tr(n)/dL_tr(n);
    A8=4*EIx_tr(n)/dL_tr(n);
    A9=0;
    %
    Kelm=[A2  0   0   0    A4   0   0   0    0    -A2 0   0   0    A4   0   0   0    0;
          0   A3  0   -A5  0    0   0   0    0    0   -A3 0   -A5  0    0   0   0    0;
          0   0   A1  0    0    0   0   0    0    0   0   -A1 0    0    0   0   0    0;
          0   -A5 0   A8   0    0   0   0    0    0   A5  0   A8/2 0    0   0   0    0;
          A4  0   0   0    A7   0   0   0    0    -A4 0   0   0    A7/2 0   0   0    0; 
          0   0   0   0    0    A6  0   0    0    0   0   0   0    0    -A6 0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    A9   0   0   0   0    0    0   0   0    -A9;
          -A2 0   0   0    -A4  0   0   0    0    A2  0   0   0    -A4  0   0   0    0;
          0   -A3 0   A5   0    0   0   0    0    0   A3  0   A5   0    0   0   0    0;
          0   0   -A1 0    0    0   0   0    0    0   0   A1  0    0    0   0   0    0;
          0   -A5 0   A8/2 0    0   0   0    0    0   A5  0   A8   0    0   0   0    0;
          A4  0   0   0    A7/2 0   0   0    0    -A4 0   0   0    A7   0   0   0    0; 
          0   0   0   0    0    -A6  0  0    0    0   0   0   0    0    A6  0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    0    0   0   0   0    0    0   0   0    0;
          0   0   0   0    0    0   0   0    -A9  0   0   0   0    0    0   0   0    A9];
    %
    % Transformace
    Kelm_T=R_tr'*Kelm*R_tr;
    Kgl(kc,kc)=Kgl(kc,kc)+Kelm_T;   % nacti lokalni matici k-teho elementu do GLL matice
end
%
%
%
%--------------------------------------------------------------------------
%              SKLADANI GLOBALNI MATICE HMOTNOSTI
%--------------------------------------------------------------------------
Mgl_s=zeros(9*pocet_nodu);
%
m=[m_vop,m_sop,m_tr];
S_eo=[S_eo_vop,S_eo_sop,S_eo_tr];
J_eo=[J_eo_vop,J_eo_sop,J_eo_tr];
S_k=[S_k_vop,S_k_sop,S_k_tr];
J_k=[J_k_vop,J_k_sop,J_k_tr];
xe=[xe_vop,xe_sop,xe_tr];
xk=[xk_vop,xk_sop,xk_tr];
Nod_ID=[Nod_ID_vop,Nod_ID_sop,Nod_ID_tr];
dL=[dL_vop,dL_sop,dL_tr];
%
% SKLADANI DO GLL MATICE HMOTNOSTI
for n=1:numel(Nod_ID)                % Poradove cislo elementu
    kc=(Nod_ID(n)*9)-8:Nod_ID(n)*9;  % kodova cisla n-teho Nodu 
    %
    if n<=pocet_nodu_vop+pocet_nodu_sop
        p=1.0;
    else
        p=0.1;
    end
    %
    KVK=(xk(n)-xe(n))*S_k(n)+J_k(n);
    %
    Mnd=dL(n)*[m(n) 0       0    0           0         0       0 0 0;
               0    m(n)    0    0           0         S_eo(n) 0 0 S_k(n);
               0    0       m(n) 0           0         0       0 0 0;
               0    0       0    0.1*J_eo(n) 0         0       0 0 0;
               0    0       0    0           p*J_eo(n) 0       0 0 0;
               0    S_eo(n) 0    0           0         J_eo(n) 0 0 KVK;
               0    0       0    0           0         0       0 0 0; 
               0    0       0    0           0         0       0 0 0;
               0    S_k(n)  0    0           0         KVK     0 0 J_k(n)];
            
    %
    if n<=pocet_nodu_vop
        Mnd_T=Mnd;                  % Transformace  VOP
    elseif n>pocet_nodu_vop && n<=(pocet_nodu_vop+pocet_nodu_sop)
        Mnd_T=R_sop2'*Mnd*R_sop2;   % Transformace  SOP
    else 
        Mnd_T=R_tr2'*Mnd*R_tr2;     % Transformace  Trup
    end    
    %   
    %
    Mgl_s(kc,kc)=Mgl_s(kc,kc)+Mnd_T;    % nacti lokalni matici k-teho elementu do GLL matice
 end
%
%
%
%--------------------------------------------------------------------------
%          PRIDANI TRASY RIZENI DO GLOBALNI MATICE TUHOSTI
%--------------------------------------------------------------------------
%
K_rizeni=zeros(9*pocet_nodu);
k_delta=[k_delta_vop,k_delta_sop,k_delta_tr];
%
for n=1:numel(Nod_ID)
       kc=Nod_ID(n)*9;
       %
    if n<=pocet_nodu_vop    %Pro nody VOP
        K_rizeni(kc,kc)=k_delta(n);
    elseif n>pocet_nodu_vop && n<=(pocet_nodu_vop+pocet_nodu_sop) %Pro nody SOP
        K_rizeni(kc-1,kc-1)=k_delta(n);
    else
      nic=0;  % Pro nody TRUPu nedelej nic
    end
end
%
%
%%
%--------------------------------------------------------------------------
%          PRIDANI UZEMNENE PRUZINY
%--------------------------------------------------------------------------
K_pruziny=zeros(9*pocet_nodu);
PRUZINY=[264  0];  %Pridani uzemnene pruziny [kodove_cislo Tuhost];
%
K_pruziny(PRUZINY(:,1),PRUZINY(:,1))=PRUZINY(:,2);
%
Kgl_s=Kgl+K_rizeni+K_pruziny;  
%
%
%--------------------------------------------------------------------------
%                APLIKACE  OKRAJOVYCH PODMINEK 
%               A MAZANI NULOVYCH RADKU/SLOUPCU
%--------------------------------------------------------------------------
%
kc_OP=(OP(:,1)-1)*9+OP(:,2);  %resp. (ND@1-1)*DOF+DOF(op)
kc_OP=kc_OP';
%
%
% ****** Nalezeni Nulovych sloupcu **************
Kgl_s_abs=abs(Kgl_s);               % Vytvorim matici tuhosti z absolutnich hodnot aby se mi nektere sloupce pri scitani nevynulovaly
SUMA=sum(Kgl_s_abs,1);            % Soucet hodnot matice Kgl v kazdem sloupci
Nulove_sloupce=find(SUMA==0);   % Vrati kodova cisla radku ktere jsou nulove
% ****** Sestaveni vektoru OP resp. kodovych cisel  **************
Vektor_OP=[kc_OP Nulove_sloupce];
%
%
% ****** APLIKACE Vektoru_OP  **************
R=9*pocet_nodu; %radky Kgl
S=R;            %sloupce Kgl, matice je ctvercova vzdy
x=1;
y=1;
%
for u=1:R
    if u~=Vektor_OP
        y=1;      
        for p=1:S
        if p~=Vektor_OP 
            Kgl_s_op(x,y)=Kgl_s(u,p);  %Na matici tuhosti
            Mgl_s_op(x,y)=Mgl_s(u,p);  %Na matici hmotnosti
            y=y+1;
        end
       end
      x=x+1;
    end
end
%
%%
%--------------------------------------------------------------------------
%                   MATICE TLUMENI
%--------------------------------------------------------------------------
ak=3.2507e-05;
am=-0.0159;
%
Tgl_s_op=ak*Kgl_s_op+am*Mgl_s_op;
%
%--------------------------------------------------------------------------
%                   MODALNI ANALYZA
%--------------------------------------------------------------------------
[VL_VEKTOR, LAMBDA]=eig(Kgl_s_op,Mgl_s_op);
%
pocet_prvku=length(Kgl_s_op);
Frekvence=zeros(pocet_prvku,1);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   VSUVKA SSM%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rad_modelu_op=size(Kgl_s_op);
%
%
%
M=Mgl_s_op;
T=zeros(rad_modelu_op);
K=Kgl_s_op;
%
% SM1
A1=[zeros(rad_modelu_op)   eye(rad_modelu_op);
    -M\K                   -M\T];
B1=[zeros(rad_modelu_op);  inv(M)];
C1=[eye(rad_modelu_op)     zeros(rad_modelu_op);
    zeros(rad_modelu_op)   eye(rad_modelu_op);
    -M\K                   -M\T];
D1=[zeros(rad_modelu_op);
    zeros(rad_modelu_op);
    inv(M)];


SM1=ss(A1,B1,C1,D1);
[VL_VEKTOR_SSM, LAMBDA_SSM]=eigs(A1,100,'sm');
LAMBDA_SSM2(:,1)=diag(LAMBDA_SSM);


x=1;
for n=1:numel(LAMBDA_SSM2)   %2*rad_modelu_op
if imag(LAMBDA_SSM(n,n))>0
    Frekvence_SSM(x,1)=(imag(LAMBDA_SSM(n,n))/2/pi);  %SSA
    LAMBDA_SSM2(n,2)=real(LAMBDA_SSM2(n,1))/imag(LAMBDA_SSM2(n,1)); %Tlumeni
    LAMBDA_SSM2(n,3)=(imag(LAMBDA_SSM2(n,1))/2/pi);  %Frekvence
    x=x+1;
end
end
Frekvence_porovnani(:,3)=sort(Frekvence_SSM);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  KONEC VSUVKA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for n=1:pocet_prvku
Frekvence(n,1)=sqrt(LAMBDA(n,n))/2/pi;
end
%
kc=1:178;
Frekvence_porovnani(kc,1)=Frekvence(kc,1);
Frekvence_porovnani(:,5)=Frekvence_porovnani(:,1)-Frekvence_porovnani(:,3);%
%
%
 disp('Frekvence_porovnani [Hz]')
 disp('  ')
 disp('Klasicky     SSM        Rozdil')
 disp('bez [T]     s [T]')
kc=1:20;
kc2=1:2:5;
Frekvence_porovnani(kc,kc2)
%
disp('Cislo podminenosti matice A1 ');
Kapa_A1=cond(A1);
Kapa_A1
%--------------------------------------------------------------------------
%                   VLASTNI TVARY KMITANI - NORMALIZACE
%--------------------------------------------------------------------------
%
VL_VEKTOR_norm=ones(pocet_prvku,pocet_prvku);
%
%
if NORMALIZACE==1
    %NORMALIZACE VLASTNIHO VEKTORU na maximum tj. "1"
    MAXIMA=max(abs(VL_VEKTOR));
    text_norm=['Normalizace vlastnich tvaru na MAXIMUM'];
        for S=1:pocet_prvku
        for R=1:pocet_prvku
            VL_VEKTOR_norm(R,S)=VL_VEKTOR(R,S)/MAXIMA(1,S);
        end
        end
% 
%
elseif NORMALIZACE==2 
    text_norm=['Normalizace vlastnich tvaru na HMOTNOST'];
    %NORMALIZACE VLASTNIHO VEKTORU na "MASS"
    for n=1:pocet_prvku
        knst=1/sqrt(VL_VEKTOR(:,n)'*Mgl_s_op*VL_VEKTOR(:,n));
        VL_VEKTOR_norm(:,n)=VL_VEKTOR(:,n)*knst;
    end
%
%
elseif NORMALIZACE==0
    text_norm=['Bez normalizace vlastnich tvaru'];
    % Zadna NORMALIZACE
        VL_VEKTOR_norm=VL_VEKTOR;
end
%
%
%
disp(text_norm)
%
%--------------------------------------------------------------------------
%                         DEFORMACE
%--------------------------------------------------------------------------
%DEFORMACE - tvorba plne modalni matice tj. VL_VEKTOR s dodanimy OP (Vektor_OP)
%          - matice DEFORMACE shrnuje vsechny vl.vektory po sloupcich
%            tj. x-ty sloupec odpovida x-temu vl. vektoru x-teho modu
%          - Tedy plna DEFORMACE vc. OP bude mit - pocet sloupcu = pocet modu a
%                                                - pocet radku = pocet nodu *9
RR=pocet_nodu*9;
SS=numel(Frekvence);
DEFORMACE=ones(RR,SS);
x=0;
%
for S=1:SS
    for R=1:RR
        if R~=Vektor_OP;
           DEFORMACE(R,S)=VL_VEKTOR_norm(R-x,S);
        else
           DEFORMACE(R,S)=0;
           x=x+1; 
        end
    end
    x=0;
end
%
%
%--------------------------------------------------------------------------
%                   VIZUALIZACE VLASTNICH TVARU
%--------------------------------------------------------------------------
%Mod=1;
for Mod=1:18
%
UX_vop=zeros(1,pocet_nodu_vop); 
UY_vop=zeros(1,pocet_nodu_vop); 
UZ_vop=zeros(1,pocet_nodu_vop); 
RZ_vop=zeros(1,pocet_nodu_vop); 
RZZ_vop=zeros(1,pocet_nodu_vop); 
UX_sop=zeros(1,pocet_nodu_sop); 
UY_sop=zeros(1,pocet_nodu_sop); 
UZ_sop=zeros(1,pocet_nodu_sop); 
RY_sop=zeros(1,pocet_nodu_sop); 
RYY_sop=zeros(1,pocet_nodu_sop); 
UX_tr=zeros(1,pocet_nodu_tr);
UY_tr=zeros(1,pocet_nodu_tr);
UZ_tr=zeros(1,pocet_nodu_tr);
RX_tr=zeros(1,pocet_nodu_tr);
%
%
%
%Extrahovani vektoru deformaci
for n=1:pocet_nodu_vop
    p=Nod_ID_vop(1,n);
    UX_vop(1,n)=DEFORMACE(9*p-8,Mod);
    UY_vop(1,n)=DEFORMACE(9*p-7,Mod)*-1;
    UZ_vop(1,n)=DEFORMACE(9*p-6,Mod);
    RZ_vop(1,n)=DEFORMACE(9*p-3,Mod)*-1;
    RZZ_vop(1,n)=DEFORMACE(9*p,Mod)*-1;
end
%
for n=1:pocet_nodu_sop
    p=Nod_ID_sop(1,n);
    UX_sop(1,n)=DEFORMACE(9*p-8,Mod);
    UY_sop(1,n)=DEFORMACE(9*p-7,Mod)*-1;
    UZ_sop(1,n)=DEFORMACE(9*p-6,Mod);
    RY_sop(1,n)=DEFORMACE(9*p-4,Mod);
    RYY_sop(1,n)=DEFORMACE(9*p-1,Mod)*-1;
end
%
for n=1:pocet_nodu_tr
    p=Nod_ID_tr(1,n);
    UX_tr(1,n)=DEFORMACE(9*p-8,Mod);
    UY_tr(1,n)=DEFORMACE(9*p-7,Mod)*-1;
    UZ_tr(1,n)=DEFORMACE(9*p-6,Mod);
    RX_tr(1,n)=DEFORMACE(9*p-5,Mod)*-1;
end
%
%Priprava dat pro plochy 
eval(['Zgl_vop_M', int2str(Mod), '=[z_vop+UZ_vop; z_vop+UZ_vop; z_vop+UZ_vop; z_vop+UZ_vop];'])
eval(['Xgl_vop_M', int2str(Mod), '=[-c_vop-xe_vop+x_p_vop+UX_vop+VT_VOP_X; x_p_vop+UX_vop+VT_VOP_X; xk_vop-xe_vop+x_p_vop+UX_vop+VT_VOP_X; c_vop-xe_vop+x_p_vop+UX_vop+VT_VOP_X];'])
eval(['Ygl_vop_M', int2str(Mod), '=[UY_vop+sin(RZ_vop).*(-c_vop-xe_vop)+VT_VOP_Y; UY_vop+VT_VOP_Y; UY_vop+sin(RZ_vop).*(xk_vop-xe_vop)+VT_VOP_Y; UY_vop+sin(RZ_vop).*(c_vop-xe_vop)+sin(RZZ_vop).*(c_vop-xk_vop)+VT_VOP_Y];'])
%--------------------------------------------------------------------------
eval(['Ygl_sop_M', int2str(Mod), '=[y_sop+UY_sop; y_sop+UY_sop; y_sop+UY_sop; y_sop+UY_sop];'])
eval(['Xgl_sop_M', int2str(Mod), '=[-c_sop-xe_sop+x_p_sop+UX_sop; x_p_sop+UX_sop; xk_sop-xe_sop+x_p_sop+UX_sop; c_sop-xe_sop+x_p_sop+UX_sop;];'])
eval(['Zgl_sop_M', int2str(Mod), '=[UZ_sop-sin(RY_sop).*(-c_sop-xe_sop); UZ_sop; UZ_sop-sin(RY_sop).*(xk_sop-xe_sop); UZ_sop-sin(RY_sop).*(c_sop-xe_sop)-sin(RYY_sop).*(c_sop-xk_sop)];'])
%--------------------------------------------------------------------------
eval(['Xgl_tr_M', int2str(Mod), '=x_tr+UX_tr;'])
eval(['Ygl_tr_M', int2str(Mod), '=[-c_tr-xe_tr+x_p_tr+UY_tr; x_p_tr+UY_tr; c_tr-xe_tr+x_p_tr+UY_tr];'])
eval(['Zgl_tr_M', int2str(Mod), '=[UZ_tr+sin(RX_tr).*(-c_tr-xe_tr); UZ_tr; UZ_tr+sin(RX_tr).*(c_tr-xe_tr)];'])
%
end
%
%Popisky pro 3D graf
ff1=['1. Mod - f = ',num2str(round(Frekvence(1,1),1)),' [Hz]'];
ff2=['2. Mod - f = ',num2str(round(Frekvence(2,1),1)),' [Hz]'];
ff3=['3. Mod - f = ',num2str(round(Frekvence(3,1),1)),' [Hz]'];
ff4=['4. Mod - f = ',num2str(round(Frekvence(4,1),1)),' [Hz]'];
ff5=['5. Mod - f = ',num2str(round(Frekvence(5,1),1)),' [Hz]'];
ff6=['6. Mod - f = ',num2str(round(Frekvence(6,1),1)),' [Hz]'];
ff7=['7. Mod - f = ',num2str(round(Frekvence(7,1),1)),' [Hz]'];
ff8=['8. Mod - f = ',num2str(round(Frekvence(8,1),1)),' [Hz]'];
ff9=['9. Mod - f = ',num2str(round(Frekvence(9,1),1)),' [Hz]'];
ff10=['10. Mod - f = ',num2str(round(Frekvence(10,1),1)),' [Hz]'];
ff11=['11. Mod - f = ',num2str(round(Frekvence(11,1),1)),' [Hz]'];
ff12=['12. Mod - f = ',num2str(round(Frekvence(12,1),1)),' [Hz]'];
ff13=['13. Mod - f = ',num2str(round(Frekvence(13,1),1)),' [Hz]'];
ff14=['14. Mod - f = ',num2str(round(Frekvence(14,1),1)),' [Hz]'];
ff15=['15. Mod - f = ',num2str(round(Frekvence(15,1),1)),' [Hz]'];
ff16=['16. Mod - f = ',num2str(round(Frekvence(16,1),1)),' [Hz]'];
ff17=['17. Mod - f = ',num2str(round(Frekvence(17,1),1)),' [Hz]'];
ff18=['18. Mod - f = ',num2str(round(Frekvence(18,1),1)),' [Hz]'];
%
%
%
%
%
if SKUPINA_GRAFU==1 || SKUPINA_GRAFU==3
%
% 9 Grafu v jednom 
figure(2)
subplot(3,3,1)
surf(Zgl_vop_M1,Xgl_vop_M1,-1*Ygl_vop_M1,'FaceColor','g');
hold on
surf(Zgl_sop_M1,Xgl_sop_M1,-1*Ygl_sop_M1,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M1',Xgl_tr_M1,-1*Ygl_tr_M1','FaceColor','[0.494 0.494 0.494]');
title(ff1);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,2)
surf(Zgl_vop_M2,Xgl_vop_M2,-1*Ygl_vop_M2,'FaceColor','g');
hold on
surf(Zgl_sop_M2,Xgl_sop_M2,-1*Ygl_sop_M2,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M2',Xgl_tr_M2,-1*Ygl_tr_M2','FaceColor','[0.494 0.494 0.494]');
title(ff2);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,3)
surf(Zgl_vop_M3,Xgl_vop_M3,-1*Ygl_vop_M3,'FaceColor','g');
hold on
surf(Zgl_sop_M3,Xgl_sop_M3,-1*Ygl_sop_M3,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M3',Xgl_tr_M3,-1*Ygl_tr_M3','FaceColor','[0.494 0.494 0.494]');
title(ff3);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,4)
surf(Zgl_vop_M4,Xgl_vop_M4,-1*Ygl_vop_M4,'FaceColor','g');
hold on
surf(Zgl_sop_M4,Xgl_sop_M4,-1*Ygl_sop_M4,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M4',Xgl_tr_M4,-1*Ygl_tr_M4','FaceColor','[0.494 0.494 0.494]');
title(ff4);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,5)
surf(Zgl_vop_M5,Xgl_vop_M5,-1*Ygl_vop_M5,'FaceColor','g');
hold on
surf(Zgl_sop_M5,Xgl_sop_M5,-1*Ygl_sop_M5,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M5',Xgl_tr_M5,-1*Ygl_tr_M5','FaceColor','[0.494 0.494 0.494]');
title(ff5);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,6)
surf(Zgl_vop_M6,Xgl_vop_M6,-1*Ygl_vop_M6,'FaceColor','g');
hold on
surf(Zgl_sop_M6,Xgl_sop_M6,-1*Ygl_sop_M6,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M6',Xgl_tr_M6,-1*Ygl_tr_M6','FaceColor','[0.494 0.494 0.494]');
title(ff6);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,7)
surf(Zgl_vop_M7,Xgl_vop_M7,-1*Ygl_vop_M7,'FaceColor','g');
hold on
surf(Zgl_sop_M7,Xgl_sop_M7,-1*Ygl_sop_M7,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M7',Xgl_tr_M7,-1*Ygl_tr_M7','FaceColor','[0.494 0.494 0.494]');
title(ff7);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,8)
surf(Zgl_vop_M8,Xgl_vop_M8,-1*Ygl_vop_M8,'FaceColor','g');
hold on
surf(Zgl_sop_M8,Xgl_sop_M8,-1*Ygl_sop_M8,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M8',Xgl_tr_M8,-1*Ygl_tr_M8','FaceColor','[0.494 0.494 0.494]');
title(ff8);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,9)
surf(Zgl_vop_M9,Xgl_vop_M9,-1*Ygl_vop_M9,'FaceColor','g');
hold on
surf(Zgl_sop_M9,Xgl_sop_M9,-1*Ygl_sop_M9,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M9',Xgl_tr_M9,-1*Ygl_tr_M9','FaceColor','[0.494 0.494 0.494]');
title(ff9);
view([x_view,y_view,z_view]);
end
%
%
%
if SKUPINA_GRAFU==2 || SKUPINA_GRAFU==3
%
% Druha varka 9-ti Grafu v jednom 
figure(3)
subplot(3,3,1)
surf(Zgl_vop_M10,Xgl_vop_M10,-1*Ygl_vop_M10,'FaceColor','g');
hold on
surf(Zgl_sop_M10,Xgl_sop_M10,-1*Ygl_sop_M10,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M10',Xgl_tr_M10,-1*Ygl_tr_M10','FaceColor','[0.494 0.494 0.494]');
title(ff10);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,2)
surf(Zgl_vop_M11,Xgl_vop_M11,-1*Ygl_vop_M11,'FaceColor','g');
hold on
surf(Zgl_sop_M11,Xgl_sop_M11,-1*Ygl_sop_M11,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M11',Xgl_tr_M11,-1*Ygl_tr_M11','FaceColor','[0.494 0.494 0.494]');
title(ff11);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,3)
surf(Zgl_vop_M12,Xgl_vop_M12,-1*Ygl_vop_M12,'FaceColor','g');
hold on
surf(Zgl_sop_M12,Xgl_sop_M12,-1*Ygl_sop_M12,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M12',Xgl_tr_M12,-1*Ygl_tr_M12','FaceColor','[0.494 0.494 0.494]');
title(ff12);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,4)
surf(Zgl_vop_M13,Xgl_vop_M13,-1*Ygl_vop_M13,'FaceColor','g');
hold on
surf(Zgl_sop_M13,Xgl_sop_M13,-1*Ygl_sop_M13,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M13',Xgl_tr_M13,-1*Ygl_tr_M13','FaceColor','[0.494 0.494 0.494]');
title(ff13);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,5)
surf(Zgl_vop_M14,Xgl_vop_M14,-1*Ygl_vop_M14,'FaceColor','g');
hold on
surf(Zgl_sop_M14,Xgl_sop_M14,-1*Ygl_sop_M14,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M14',Xgl_tr_M14,-1*Ygl_tr_M14','FaceColor','[0.494 0.494 0.494]');
title(ff14);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,6)
surf(Zgl_vop_M15,Xgl_vop_M15,-1*Ygl_vop_M15,'FaceColor','g');
hold on
surf(Zgl_sop_M15,Xgl_sop_M15,-1*Ygl_sop_M15,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M15',Xgl_tr_M15,-1*Ygl_tr_M15','FaceColor','[0.494 0.494 0.494]');
title(ff15);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,7)
surf(Zgl_vop_M16,Xgl_vop_M16,-1*Ygl_vop_M16,'FaceColor','g');
hold on
surf(Zgl_sop_M16,Xgl_sop_M16,-1*Ygl_sop_M16,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M16',Xgl_tr_M16,-1*Ygl_tr_M16','FaceColor','[0.494 0.494 0.494]');
title(ff16);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,8)
surf(Zgl_vop_M17,Xgl_vop_M17,-1*Ygl_vop_M17,'FaceColor','g');
hold on
surf(Zgl_sop_M17,Xgl_sop_M17,-1*Ygl_sop_M17,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M17',Xgl_tr_M17,-1*Ygl_tr_M17','FaceColor','[0.494 0.494 0.494]');
title(ff17);
view([x_view,y_view,z_view]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(3,3,9)
surf(Zgl_vop_M18,Xgl_vop_M18,-1*Ygl_vop_M18,'FaceColor','g');
hold on
surf(Zgl_sop_M18,Xgl_sop_M18,-1*Ygl_sop_M18,'FaceColor','[0.871 0.49 0.0]');
hold on
surf(Zgl_tr_M18',Xgl_tr_M18,-1*Ygl_tr_M18','FaceColor','[0.494 0.494 0.494]');
title(ff18);
view([x_view,y_view,z_view]);

else
disp('   ')
end



if VYBER_MOD==0
    disp('KONEC')
else
    Z_vop_samostatny=eval(['Zgl_vop_M',int2str(VYBER_MOD)]);
    X_vop_samostatny=eval(['Xgl_vop_M',int2str(VYBER_MOD)]);
    Y_vop_samostatny=eval(['Ygl_vop_M',int2str(VYBER_MOD)]);
    Z_sop_samostatny=eval(['Zgl_sop_M',int2str(VYBER_MOD)]);
    X_sop_samostatny=eval(['Xgl_sop_M',int2str(VYBER_MOD)]);
    Y_sop_samostatny=eval(['Ygl_sop_M',int2str(VYBER_MOD)]);
    Z_tr_samostatny=eval(['Zgl_tr_M',int2str(VYBER_MOD)]);
    X_tr_samostatny=eval(['Xgl_tr_M',int2str(VYBER_MOD)]);
    Y_tr_samostatny=eval(['Ygl_tr_M',int2str(VYBER_MOD)]);
    popisek=eval(['ff',int2str(VYBER_MOD)]);
    %
    %Samostatny graf
    figure(1)
    surf(Z_vop_samostatny,X_vop_samostatny,-1*Y_vop_samostatny,'FaceColor','g');
    hold on
    surf(Z_sop_samostatny,X_sop_samostatny,-1*Y_sop_samostatny,'FaceColor','[0.871 0.49 0.0]');
    hold on
    surf(Z_tr_samostatny',X_tr_samostatny,-1*Y_tr_samostatny','FaceColor','[0.494 0.494 0.494]');
    title(popisek);
    view([x_view,y_view,z_view]);
end
disp('KONEC')