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 Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by