%  Stress Transformations

%  Here is a transformation matrix, which corresponds to
%  a rotation in the xy plane of angle theta.

theta = 20*pi/180;

Q = [  cos(theta)  -sin(theta)   0
       sin(theta)   cos(theta)   0
                0            0   1 ]

%  Another transformation matrix which corresponds to a
%  rotation in the xz plane of angle phi

phi = 40*pi/180;

R  = [ cos(phi)    0   sin(phi)
               0   1          0
       -sin(phi)  0   cos(phi) ]
    
%  A composition of the two coordinate rotations.

T = Q*R

%  Simple uniaxial stress state

sigma = [1000 0 0; 0 0 0; 0 0 0]

%  Stress transformation using the T- matrix

sigma_p = T' * sigma * T