Help Creating Global Stiffness Matrix

I need help assembling this stiffness matrix. This is a generic stiffness matrix where ho is the outside air and k1,k2,k3 is the conductivity and the n represent the number of nodes in the materials. This is for a 1D wall. Thank you!

5 Comments

Do you know the number of nodes, parameter values etc? Or are you expected to write generic code that will build this for any number of nodes?
Hi Andy,
I don't know the number of nodes. I just want to write a generic code that will build this for any number of nodes like you said. I wrote the code for the small k(K1,K1,K3,etc..) Now I need to create the big matrix [K]. Here is what I have so far:
%%Wall_Characteristics
%-------------------------------------------------------------------------%
clear variables
close all
clc
%-------------------------------------------------------------------------%
% define variables
A = 1; % Cross section area
m = 4; % mass
dx = .125; % segment length, Inches
to= 60; % outside air temperature, Fahrenheit
ti= 70; % inside air temperature, Fahrenheit
alpha = 0.25; % wall absorptivity - solar heat gain layer n (last node)
hoa = 3.522; % Outside Air Surface Resistance, Hoa = BTU/(Hr*FT2*F)
hia = 1.761; % Inside Air Surface Resistance, Hia = BTU/(Hr*FT2*F)
l=1; % wall length, ft
h=1; % wall height, ft
t_i=70; % [°F] Temperature, fluid inside
t_o=80; % [°F] Temperature, fluid outside
n=5
%-------------------------------------------------------------------------%
% For Each Layer--Start From Outside to Inside
% Outside Layer---
d1 = 120.0; % wall density, lb / ft^3
cp1 = 0.19; % specific heat, Btu/lb-deg F
k1 = 9.907; % thermal conductivity, k BTU-in/(Hr*FT2*F)
n1 = 5; % # of nodes
th1 = dx*n1; % thickness of each layer
% 2nd Layer---Common Brick
d2 = 120.0; % wall density, lb / ft^3
cp2 = 0.19; % specific heat, Btu/lb-deg F
k2 = 0.8; % thermal conductivity, k BTU-in/(Hr*FT2*F)
n2 = 28; % # of nodes
th2 = dx*n2; % thickness of each layer
% 3rd Layer---Insulation
d3 = 5.3; % wall density, lb / ft^3
cp3 = 0.23; % specific heat, Btu/lb-deg F
k3 = 0.333; % thermal conductivity, k BTU-in/(Hr*FT2*F)
n3 = 28; % # of nodes
th3 = dx*n3; % thickness of each layer
% 4th Layer---Inside Layer
d4 = 5.3; % wall density, lb / ft^3
cp4 = 0.23; % specific heat, Btu/lb-deg F
k4 = 0.25; % thermal conductivity, k, BTU-in/(Hr*FT2*F)
n4 = 5; % # of nodes
th4 = dx*n4; % thickness of each layer
%-------------------------------------------------------------------------%
%Generic heat conductivity matrix [K]
% K = [ hoa -hoa 0 0 0 0 0 0 0 0 0 0
% -hoa hoa+k1 -k1 0 0 0 0 0 0 0 0 0
% 0 -k1 k1+k2 -k2 0 0 0 0 0 0 0 0
% 0 0 -k2 k2+k3 -k3 0 0 0 0 0 0 0
% 0 0 0 -k3 k3+k4 -k4 0 0 0 0 0 0
% 0 0 0 0 -k4 k4+k5 -k5 0 0 0 0 0
% 0 0 0 0 0 (-k(n-1)) (k(n-1)+k*n) (-k*n) 0 0 0 0
% 0 0 0 0 0 0 (-k(n-1)) (k(n-4)+k(n-3)) (-k(n-2)) 0 0 0
% 0 0 0 0 0 0 0 (-k(n-3)) (k(n-3)+k(n-2)) (-k(n-2)) 0 0
% 0 0 0 0 0 0 0 0 -k(n-2) (k(n-2)+k(n-1)) (-k(n-1)) 0
% 0 0 0 0 0 0 0 0 0 (-k(n-1)) (k(n-1)+hia) -hia;
% 0 0 0 0 0 0 0 0 0 0 -hia hia ];
%-------------------------------------------------------------------------%
for A = [1:n1+1];
k(A)=k1/dx;
end
for B = [n1+2:n1+n2+1];
k(B) = k2/dx;
end
for C = [n1+n2+2:n1+n2+n3+1];
k(C) = k3/dx;
end
for D = [n1+n2+n3+2:n1+n2+n3+n4+1];
k(D) = k4/dx;
end
disp(k)
Can you confirm for me the difference between k(n-1) and k(N-1)? What size should the matrix should be for example, with 4 layers - conductivities k1 - k4?
Caden
Caden on 8 Aug 2014
Edited: Caden on 8 Aug 2014
There is no difference between k(n-1) and k(N-1). n or N is just the # of nodes. I want to be able to size the matrix according to how many layers there are. As you can see in the image below, there are 9 layers and 12 nodes. Again this is a 1D heat transfer.
Thanks for clarifying.

Sign in to comment.

Answers (1)

Andy L
Andy L on 8 Aug 2014
First of all I would like to point out I don't know much about stiffness matrices - I've never had to use them before. There may well be an easier way to do this, however my approach would be as such.
I would start with making my .m file a function - if you set the input to varargin you can pass your function a variable vector of values. This would contain your h_oa, h_ia, k_n & T_n variables. You should then be able to determine the length of your stiffness and temperature matrix, which in turn gives you both dimensions (it is square). You can then initialise with zeros - this gives you a matrix of zeros of the appropriate dimensions.
Then you would need to use a for loop and indexing, placing the variables in as appropriate to build up the diagonal values of your stiffness matrix. As for the temperature matrix that could be made from the latter half of the varargin argument!

Asked:

on 7 Aug 2014

Commented:

on 11 Aug 2014

Community Treasure Hunt

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

Start Hunting!