% Problem 2

eps = [ 100 250 -50
        250 -400 80
        -50  80 -200]

%  a Pricnipal Strains

prins = eigs(eps)

ep1 = prins(3)
ep2 = prins(2)
ep3 = prins(1)

% b Maximum Shear Strain

gamma_max = ep1-ep3

% c Volumetric strain

evol = ep1+ep2+ep3

%  d Deviatoric strain tensor

eps_dev = eps - evol * eye(3)

% e Stresses

E = 1.e7
nu = 0.3
lambda = E*nu/((1-2*nu)*(1+nu))
G = E/(2*(1+nu))

ex = eps(1,1)*1.e-6;
ey = eps(2,2)*1.e-6;
ez = eps(3,3)*1.e-6;
gxy = eps(1,2)*2e-6;
gxz = eps(1,3)*2e-6;
gyz = eps(2,3)*2e-6;

e = ex + ey + ez;

sx = 2*G*ex + lambda*e;
sy = 2*G*ey + lambda*e;
sz = 2*G*ez + lambda*e;

txy = G*gxy;
txz = G*gxz;
tyz = G*gyz;

sigma = [ sx txy txz
          txy sy tyz
          txz tyz sz]
          
          
% f

strain = 1.e-6 * eps
U0 = 1/2 * sum(sum(strain.*sigma))

