Vous êtes sur la page 1sur 2

%MEL 424 IIT Ropar % Nodal Coordinates (x,y) for all the nodes clear all; format long;

X_mat = [2.54 0; % Means first node's coordinates is (2.54, 0) 0 0; 0 2.54]; %Nodal Connectivity for all the elements C_mat = [2 3; %Means the First element has these two nodes: node nos. 2 and 3 2 1; 1 3]; E_vec = [6.9e+10 20.7e+10 20.7e+10]; %Young's Modulus for all the elements A_vec = [32.3 38.7 25.8]*1e-4; %Area for all the elements nNodes = size(X_mat,1); % Total no. of nodes nEle = size(C_mat,1); %Total no. of elements nDOF = 2*nNodes; K_ele_local_mat = zeros(2,2); %The local stiffness matrix for an element K_ele_global_mat = zeros(4,4); %The global stiffness matrix for the element K_truss_global_mat = zeros(nDOF, nDOF); %The ASSEMBLED global stiffness matrix f or the whole truss force_truss_global_vec = zeros(nDOF, 1); disp_truss_global_vec = zeros(nDOF, 1); dof_all = [1:2*nNodes]; dof_fixed = [3 4 5 6]; %degrees of freedom which are fixed dof_free = setdiff(dof_all, dof_fixed); %External Forces Prescribed: force_truss_global_vec( dof_free, 1 ) = [22.2 -111]*10^3; length_vec = zeros(nEle, 1); angle_vec = zeros(nEle, 1); for i = 1:nEle %For every element, compute the following node1 = C_mat(i,1); % First node of the ith element node2 = C_mat(i,2); % Second node of the ith element x1 y1 x2 y2 = = = = X_mat( X_mat( X_mat( X_mat( node1, node1, node2, node2, 1); 2); 1); 2); % % % % x-coordinate y-coordinate x-coordinate y-coordinate of of of of the the the the first node first node second node second node

dy = y2 - y1; dx = x2 - x1; Length = sqrt(dx^2 + dy^2); %Length of the element length_vec(i) = Length; Angle = atan2( dy, dx ); %Angle the element makes to x-direction R_mat = [ cos(Angle) sin(Angle) 0 0; 0 0 cos(Angle) sin(Angle) ]; %Transformation matrix k = E_vec(i)*A_vec(i)/Length; K_ele_local_mat = k*[1 -1; -1 1]; %Local stiffness (2x2) matrix for the elem

ent K_ele_global_mat = R_mat'*K_ele_local_mat*R_mat; dof_vec = [node1*2-1 node1*2 node2*2-1 node2*2]; %Assembly of the Global stiffness (4x4) matrix for the whole truss: K_truss_global_mat( dof_vec, dof_vec ) = K_truss_global_mat( dof_vec, dof_ve c ) + K_ele_global_mat; end %Compute Displacement disp_truss_global_vec(dof_free) = K_truss_global_mat(dof_free, dof_free) \ force _truss_global_vec(dof_free); %same as %disp_truss_global_vec(dof_free) = inv(K_truss_global_mat(dof_free, dof_free))*f orce_truss_global_vec(dof_free) %Compute Reaction Forces at the nodes where the truss is fixed force_truss_global_vec(dof_fixed) = K_truss_global_mat(dof_fixed, dof_free) * di sp_truss_global_vec(dof_free); %Now Strain and Stress strain_vec = zeros(nNodes,1); stress_vec = zeros(nNodes,1); for i = 1:nEle node1 = C_mat(i,1); % First node of the ith element node2 = C_mat(i,2); % Second node of the ith element dof_vec = [node1*2-1 node1*2 node2*2-1 node2*2]; disp_ele_local_vec = R_mat*disp_truss_global_vec(dof_vec); strain_vec(i) = (disp_ele_local_vec(2)-disp_ele_local_vec(1))/length_vec(i); stress_vec(i) = E_vec(i)*strain_vec(i); end %Print Output K_truss_global_mat disp_truss_global_vec force_truss_global_vec strain_vec stress_vec

Vous aimerez peut-être aussi