
clear
a=4;
b=3;
x1=-a;
y1=-b;
//u11, v11, u12, v12, u22, v22, u21, v21,
Elm1=1/(4*a*b)*[-(b-y1) 0 +(b-y1) 0 (b+y1) 0 -(b+y1) 0; 0 -(a-x1) 0 -(a+x1) 0 (a+x1) 0 (a-x1); -(a-x1) -(b-y1) -(a+x1) (b-y1) (a+x1) (b+y1) (a-x1) -(b+y1)]



x2=-3*a;
y2=-3*b;
//u12, v12, u13, v13, u23, v23, u22, v22,
Elm2=1/(4*a*b)*[-(b-y2) 0 +(b-y2) 0 (b+y2) 0 -(b+y2) 0; 0 -(a-x2) 0 -(a+x2) 0 (a+x2) 0 (a-x2); -(a-x2) -(b-y2) -(a+x2) (b-y2) (a+x2) (b+y2) (a-x2) -(b+y2)]



//u11, v11, u12, v12, u22, v22, u21, v21,
//u12, v12, u13, v13, u23, v23, u22, v22,

//u11, v11, u12, v12, u22, v22, u21, v21, u13, v13, u23, v23,

//B=1/(4*a*b)*[-(b-y1) 0  (b-y1)-(b-y2) 0+0 (b+y1)-(b+y2) 0+0 -(b+y1) 0 +(b-y2) 0 (b+y2) 0 ;
//            0 -(a-x1) 0+0 -(a-x2)-(a+x1) 0+0 (a-x2)+(a+x1) 0 (a-x1) 0 -(a+x2) 0 (a+x2);
//            -(a-x1) -(b-y1) -(a+x1)-(a-x2) -(b-y2)+(b-y1) (a+x1)+(a-x2) -(b+y2)+(b+y1) (a-x1) -(b+y1) -(a+x2) (b-y2) (a+x2) (b+y2)]
//B_inv=B'

//u11, v11, u12, v12, u22, v22, u21, v21, u13, v13, u23, v23,
//Mat_B=[Elm1_u11 Elm1_v11 Elm1_u12+Elm2_u12 Elm1_v12+Elm2_v12 Elm1_u22+Elm2_u22 Elm1_v22+Elm2_v22 Elm1_u21 Elm1_v21 Elm2_u13 Elm2_v13 Elm2_u23 Elm2_v23]
E=200000
nu=0.33


M_E=E/((1+nu)*(1-2*nu))*[(1-nu) nu 0; nu (1-nu) 0; 0 0 (1-2*nu)/2]

K_1=Elm1'*M_E*Elm1
K_2=Elm2'*M_E*Elm2

//both system of equation

    //block element 1

        block_1_a=[K_1(1,1) K_1(1,2);K_1(2,1) K_1(2,2)];
        block_1_b=[K_1(1,3) K_1(1,4);K_1(2,3) K_1(2,4)];
        block_1_c=[K_1(1,5) K_1(1,6);K_1(2,5) K_1(2,6)];
        block_1_d=[K_1(1,7) K_1(1,8);K_1(2,7) K_1(2,8)];
        block_1_e=[K_1(3,3) K_1(3,4);K_1(4,3) K_1(4,4)];
        block_1_f=[K_1(3,5) K_1(3,6);K_1(4,5) K_1(4,6)];
        block_1_g=[K_1(3,7) K_1(3,8);K_1(3,7) K_1(3,8)];
        block_1_h=[K_1(5,5) K_1(5,6);K_1(6,5) K_1(6,6)];
        block_1_i=[K_1(5,7) K_1(5,8);K_1(6,7) K_1(6,8)];
        block_1_j=[K_1(7,7) K_1(7,8);K_1(8,7) K_1(8,8)];



    //block element 1

        block_2_a=[K_2(1,1) K_2(1,2);K_2(2,1) K_2(2,2)];
        block_2_b=[K_2(1,3) K_2(1,4);K_2(2,3) K_2(2,4)];
        block_2_c=[K_2(1,5) K_2(1,6);K_2(2,5) K_2(2,6)];
        block_2_d=[K_2(1,7) K_2(1,8);K_2(2,7) K_2(2,8)];
        block_2_e=[K_2(3,3) K_2(3,4);K_2(4,3) K_2(4,4)];
        block_2_f=[K_2(3,5) K_2(3,6);K_2(4,5) K_2(4,6)];
        block_2_g=[K_2(3,7) K_2(3,8);K_2(3,7) K_2(3,8)];
        block_2_h=[K_2(5,5) K_2(5,6);K_2(6,5) K_2(6,6)];
        block_2_i=[K_2(5,7) K_2(5,8);K_2(6,7) K_2(6,8)];
        block_2_j=[K_2(7,7) K_2(7,8);K_2(8,7) K_2(8,8)];

    //neutre

        Neutral=[0 0;0 0];

    //both matrice

        K=[ block_1_a      block_1_b       Neutral   block_1_d       block_1_c Neutral;
            block_1_b' block_1_e+block_2_a  block_2_b block_1_g block_1_f+block_2_d  block_2_c
            Neutral        block_2_b'       block_2_e Neutral       block_2_g block_2_f;
            block_1_d'      block_1_g'       Neutral   block_1_j     block_1_i Neutral;
            block_1_c' block_1_f'+block_2_d'  block_2_g' block_1_i' block_1_h+block_2_j  block_2_i;
            Neutral        block_2_c'       block_2_f' Neutral       block_2_i' block_2_h']


M_k_d=bdiag(K)

det(K)

inv(K)
