Creating a global stiffness matrix
16 views (last 30 days)
Show older comments
I want to write a program to generate a 'global stiffness matrix of a 1 dimensional 2 noded n number of elements where the input will be coordinates of the nodes, area of cross section and Youngs modulus. I have written the following code but it has some errors. Please let me know how to proceed.
clc
clear
disp('Global Stiffness Matrix for a 2 noded 1-D element')
n=input('Enter the number of elements: ');
A=input('Enter the cross-sectional area of the element in mm^2: ');
E=input('Enter the Youngs Modulus of the element in N/mm^2: ');
for i=1:n
x(i)=input('Enter x coordinate');
y(i)=input('Enter y coordinate');
end
k=[1 -1;-1 1];
for i=1:n
k(i)=((A*E)/L(i))*k;
end
Kg=zeros(n+1);
for i=1:n
Kg(i:i+1,i:i+1)=Kg(i:i+1,i:i+1)+k(i);
end
disp('The global stiffness matrix is:')
Kg
1 Comment
Yukthi S
on 19 Apr 2024
I see that you did not define "L" in the code. Assuming that "L" is the length of elements,I modifed the code. You can try it.
clc;
clear;
disp('Global Stiffness Matrix for a 2 noded 1-D element');
n = input('Enter the number of elements: ');
A = input('Enter the cross-sectional area of the element in mm^2: ');
E = input('Enter the Youngs Modulus of the element in N/mm^2: ');
% Initialize arrays for node coordinates
x = zeros(1, n+1); % Assuming linear elements, n+1 nodes
% Input node coordinates
for i = 1:n+1
x(i) = input(['Enter x coordinate of node ', num2str(i), ': ']);
end
% Initialize global stiffness matrix
Kg = zeros(n+1);
% Element stiffness matrix calculation and assembly into global matrix
for i = 1:n
% Length of the element
L = abs(x(i+1) - x(i));
% Local stiffness matrix for the current element
k_local = (A*E/L)*[1 -1; -1 1];
% Assembly into global stiffness matrix
Kg(i:i+1, i:i+1) = Kg(i:i+1, i:i+1) + k_local;
end
disp('The global stiffness matrix is:');
disp(Kg)
Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!