%  Day 5 Example Problem

%  Three dimensional state of stress


sigma = [  80  40  -30
            40  50  20
            -30   20  -10 ]
         

 
 
 %  Use  stress transformations and eigens.
 
 [V,D]=eigs(sigma);
 smax = max( diag(D) );
 smin = min(diag(D));
 taumax = (smax-smin)/2
 
%  Here I'm assuming largest principal stress is the first.
%  And second principal stress is next.  What we need is a
%  rotation about the direction of the middle principal
% stress.

a = sqrt(2)/2;
R = [a 0 -a; 0 1 0; a 0 a];


% Here's a coordinate transformation between the 
% direction of max shear stress and the orig xyz

Q = V*R

% Test it

n1 = Q(:,1);
p1 = sigma * n1;
sn1 = n1' * p1;
tau_test = sqrt( norm(p1)^2 - sn1^2)

% Now let's take a look at the octahedral shear stresses.

noct = [1/sqrt(3) 1/sqrt(3) 1/sqrt(3) ]'
no = V*noct;
po = sigma * no;
sigoct = no'*po;
tauoct = sqrt( norm(po)^2 - sigoct^2);
tau_oct = 1/3*sqrt( (D(1,1)-D(2,2))^2 + ...
                    (D(2,2)-D(3,3))^2 + ...
                    (D(3,3)-D(1,1))^2 );
