% thin steel meter stick				% Rowin Andruscavage
												% MAE 470 SP01
												% Problem Set 3

L = 1;		% [m] length
b = 0.06;	% [m] width
h = 0.001;	% [m] height / thickness
E = 182e9;	% [N/m^2] Young's modulus of elasticity
nu = 0.3;	% Poisson's ratio

A = b*h;		% [m^2] area
J = 4 * ((h/2)^3*b/2 + h/2*(b/2)^3) / 3;	% torsional elasticity
G = E / (2*(1+nu));	% torsional deformation
Iz = b*h^3/12;			% bending stiffness in xy plane
Iy = b^3*h/12;			% bending stiffness in xz plane

% part A, construction of stiffness submatrices
% part A(1)
Ktension = zeros (12,12);
Ktension(1,1) = 1; 	Ktension(1,7) = -1;
Ktension(7,1) = -1; 	Ktension(7,7) = 1;
Ktension = E*A/L .* Ktension;

% part A(2)
Ktorsion = zeros (12,12);
Ktorsion(4,4) = 1; 	Ktorsion(4,8) = -1;
Ktorsion(8,4) = -1;	Ktorsion(8,8) = 1;
Ktorsion = J*G/L .* Ktorsion;

% part A(3)
Kbendxy = [
   zeros(1,12)
   0 12/L^3 0 0 0 6/L^2 0 -12/L^3 0 0 0 6/L^2
   zeros(3,12)
   0 6/L^2 0 0 0 4/L 0 -6/L^2 0 0 0 2/L
   zeros(1,12)
   0 -12/L^3 0 0 0 -6/L^2 0 12/L^3 0 0 0 -6/L^2
   zeros(3,12)
   0 6/L^2 0 0 0 2/L 0 -6/L^2 0 0 0 4/L ];
Kbendxy = E*Iz .* Kbendxy;

% part A(4)
Kbendxz = [
   zeros(2,12)
   0 0 12/L^3 0 6/L^2 0 0 0 -12/L^3 0 6/L^2 0
   zeros(1,12)
   0 0 6/L^2 0 4/L 0 0 0 -6/L^2 0 2/L 0
   zeros(3,12)
   0 0 -12/L^3 0 -6/L^2 0 0 0 12/L^3 0 -6/L^2 0
   zeros(1,12)
   0 0 6/L^2 0 2/L 0 0 0 -6/L^2 0 4/L 0 
	zeros(1,12) ];
Kbendxz = E*Iy .* Kbendxz;

% part B, superposition of matrices :
K = Ktension + Ktorsion + Kbendxy + Kbendxz;

% part C, rotate into singular matrix by 30 degrees in Z axis
a = 30/180 * pi;
A3D = [ 
   cos(a) cos(-90+a) 0
   cos(90+a) cos(a) 0
   0 0 1 ];
A = zeros(12,12);
A(1:3,1:3) = A3D;	A(4:6,4:6) = A3D;	A(7:9,7:9) = A3D; A(10:12,10:12) = A3D;
Kstar = A * K * A';

save ps3.mat Ktension Ktorsion Kbendxy Kbendxz K Kstar -ASCII -TABS