function [ S1, S2, S3, T12, T23, T13 ] = PrnStresses (Sx, Sy, Sz, Txy, Tyz, Tzx)
%
%  This function uses applied stresses to compute the pricipal stresses 
%  and shears.  The maximum principal stress is S1 and the maximum
%  principal shear is T13.
%
%  Input
%    Sx, Sy, Sz       the applied normal stresses
%    Txy, Tyz, Tzs    the applied shear stresses
%
%  Output
%    S1, S2, S3        the principal stresses
%    T12, T23, T13     the principal shear stresses

c(1) = 1;
c(2) = -(Sx + Sy + Sz);
c(3) = -(Txy^2 + Tyz^2 + Tzx^2 - Sx*Sy - Sy*Sz - Sz*Sx);
c(4) = -(Sx*Sy*Sz + 2*Txy*Tyz*Tzx - Sx*Tyz^2 - Sy*Tzx^2 - Sz*Txy^2);

%  Compute the roots of the polynomial

r = roots(c);

%  Arrange in order

s = sort(r);

S1 = s(3);
S2 = s(2);
S3 = s(1);

T13 = abs((S1 - S3)/2);
T12 = abs((S2 - S1)/2);
T23 = abs((S3 - S2)/2);

end

