Question: What is wrong with my matlab code?Problem 2 . 7 P = 7 . 1 0 ^ 3 ; % Applied load in N E

What is wrong with my matlab code?Problem 2.7
P =7.10^3; % Applied load in N
E =1.5*10^11; % Young's modulus in Pa
A =10^(-2); % Cross-sectional area in m^2
L =3; % Length of each square in m
W =4; % Width of the rectangle in m
% Define node coordinates
nodes =[00; L 0; 2*L 0; 3*L 0; 4*L 0; 0 L; L L; 2*L L; 3*L L; 4*L L];
% Define element connectivity
elements =[12; 23; 34; 45; 16; 27; 38; 49; 510; 67; 78; 89; 910];
numNodes = size(nodes,1);
numElements = size(elements,1);
K = zeros(2*numNodes);
F = zeros(2*numNodes,1);
for i =1:numElements
node1= elements(i,1);
node2= elements(i,2);
x1= nodes(node1,1);
y1= nodes(node1,2);
x2= nodes(node2,1);
y2= nodes(node2,2);
L = norm([x2- x1, y2- y1]);
cosTheta =(x2- x1)/ L;
sinTheta =(y2- y1)/ L;
k =(E A / L)[cosTheta^2 cosTheta*sinTheta; cosTheta*sinTheta sinTheta^2];
% Assemble into global stiffness matrix
index =[2*node1-1,2*node1,2*node2-1,2*node2];
K(index, index)= K(index, index)+ k;
% Apply nodal loads
F(2*node2-1)= F(2*node2-1)+ P * cosTheta;
F(2*node2)= F(2*node2)+ P * sinTheta;
end
penalty =1e9; % Adjust this value as needed
fixedNode =1; % Assuming the first node is fixed
K(fixedNode*2-1, :) =0;
K(:, fixedNode*2-1)=0;
K(fixedNode*2-1, fixedNode*2-1)= penalty;
K(fixedNode*2, :) =0;
K(:, fixedNode*2)=0;
K(fixedNode*2, fixedNode*2)= penalty;
F(fixedNode*2-1)=0;
F(fixedNode*2)=0;
U = K \ F;
stresses = zeros(numElements,1);
for i =1:numElements
node1= elements(i,1);
node2= elements(i,2);
x1= nodes(node1,1);
y1= nodes(node1,2);
x2= nodes(node2,1);
y2= nodes(node2,2);
L = norm([x2- x1, y2- y1]);
cosTheta =(x2- x1)/ L;
sinTheta =(y2- y1)/ L;
strain =([cosTheta sinTheta][U(2node2-1); U(2*node2)]-[cosTheta sinTheta][U(2node1-1); U(2*node1)])/ L;
stresses(i)= E * strain;
end
mag =1000; % Magnification factor for better visualization
defNodes = nodes + mag * reshape(U,[],2);
figure;
hold on;
for i =1:numElements
node1= elements(i,1);
node2= elements(i,2);
plot([nodes(node1,1), nodes(node2,1)],[nodes(node1,2), nodes(node2,2)],'b-', 'LineWidth', 1);
end
for i =1:size(defNodes,1)
plot(defNodes(i,1), defNodes(i,2),'ro', 'MarkerSize', 5);
end
xlabel('x (m)');
ylabel('y (m)');
title('Deformed Structure');
axis equal;
grid on;
 What is wrong with my matlab code?Problem 2.7 P =7.10^3; %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!