Creating a global stiffness matrix

17 次查看(过去 30 天)
Rohit Raut
Rohit Raut 2021-4-9
评论: Yukthi S 2024-4-19
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 个评论
Yukthi S
Yukthi S 2024-4-19
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)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by