Creating a global stiffness matrix

조회 수: 16 (최근 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