Professional Documents
Culture Documents
●
23
MATLAB1 is a popular software currently being used for solving a variety of engineering
analysis problems. This chapter presents 10 MATLAB programs for the finite element
analysis of different types of problems discussed in Chapters 1 to 20. The programs are
given in the form of m-files. Each program requires subprograms, again in the form of
m-files, for solving a problem. In addition, depending on the problem to be solved, the
user needs to create a main program, in the form of an m-file, to specify the input data,
call the relevant program (m-file), and display the results. Sample main programs are given
for all 10 programs described in this chapter. The m-files of the programs and all the
subprograms needed for executing the programs are available at the web site of the book.
The programs and the purpose or use of the programs are given below.
1
MATLAB is a registered trademark of The MathWorks, Inc., 3 Apple Hill drive, Natick, MA 01760-2098.
Relevant Location
Program Program in the Book
Number Name (Section Number) Use of the Program
1 choleski.m 7.2.2 To solve a symmetric system of algebraiciequations with several
! h! ! !
right-side vectors, ½A X = b 1 , b 2 , ::: , b M ; ½A can be stored in
banded form
2 adjust.m 6.3 To incorporate boundary conditions (specified values to boundary
! !
degrees of freedom) in matrix equations ½A X = b where the
matrix ½A can be stored in banded form
3 truss3D.m 9.2 Analysis of 3D trusses (to find displacements of nodes and
stresses in bar elements)
4 cst.m 10.3.1 Displacement and stress analysis of plates lying in XY plane
subjected to in-plane loads using linear triangular (CST) elements
5 CST3D.m 10.3.3 Displacement and stress analysis of three-dimensional box-type
of structures subjected to nodal loads using linear triangular (CST)
elements
6 heat1.m 14.2 Temperature distribution in 1D fins (by considering conduction
and convection)
7 radiat.m 14.6 Temperature distribution in 1D fins by considering radiation heat
transfer (along with conduction and convection)
8 heat2.m 15.2 Temperature distribution in 2D plates with arbitrary geometry
using linear triangular elements (by considering conduction and
convection)
9 phiflo.m 18.3 Confined fluid flow around a cylinder (or any shaped body) for
inviscid and incompressible fluids using potential function
approach using linear triangular elements
10 torson.m 20.3 Stress function variation in a cross-section of a solid prismatic
684 shaft subjected to twisting moment using linear triangular
elements
! ! ! !
to be solved for any right-hand-side vector b can be expressed as ½A X = ½UT ½U X = b : These
equations can be solved as
! ! !
½U X = ð½UT Þ–1 b ≡ Z (23.2)
and
! !
X = ½U–1 Z
! !
In the subprogram, solve.m, the vectors Z i for different b i are found in the forward pass
! !
and are stored in the array B. The solutions X i corresponding to different b i are found in
the backward pass and are stored in the array B. Thus, the columns of the array B returned
!
from solve.m will give the desired solutions X i , i = 1, 2, … , M. A main program, named
main_choleski.m, is created to provide the input data, call the subprograms decomp.m and
solve.m, and obtain the results. The procedure is illustrated with the following example.
EXAMPLE 23.1
Solve the following system of equations:
2 3
1 −1 0 0 0
6 −1 2 −1 0 07
6 7! !
6 7
6 0 −1 2 −1 0 7 Xi = b i (E.1)
6 7
4 0 0 −1 2 −1 5
0 0 0 −1 2
where
8 9 8 9 8 9 8 9
> x1 > > 1> > 0> > 1>
>
> >
> >
> >
> >
> >
> >
> >
>
>
> >
> >
> 0>> >
> 0>> >
> 1>>
>
< x2 >
= >
< >
= >
< >
= >
< >
=
! ! ! ! 685
X i = x3 , b1 = 0 , b2 = 0 , and b 3 = 1
>
> >
> >
> >
> >
> >
> >
> >
>
>
> x4 >
> >
>0> > >
>0> > >
>1> >
>
> > >
> > >
> > >
> >
: > ; : > ; : > ; : > ;
x5 i 0 1 1
Here the number of equations = N = 5, the semi-bandwidth of [A] = NB = 2, and the number of
!
vectors b i = M = 3.
Solution
A listing of the program main_choleski.m created for solving the system of Eq. (E.1) and the results
obtained are shown below.
for j = 1:M
fprintf (‘%s’, ‘solution’)
fprintf (‘%2. 0f’, j’)
fprintf (‘%s\n’,‘:’)
(Continued )
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
Solution 1:
5 4 3 2 1
Solution 2:
1 1 1 1 1
Solution 3:
15 14 12 9 5
NOTES
686 1. If the prescribed values of several degrees of freedom are to be incorporated, the program adjust.m
is to be used once for each prescribed degree of freedom.
2. The program adjust.m incorporates the boundary conditions using the procedure described in
Method 2 of Section 6.3.
3. The program works even when the matrix [A] is not stored in band form. If [A] is not stored in
band form, then the bandwidth of A can be defined as NB = NN and the full original matrix [A]
can be treated as if it is in band form.
The following example illustrates the use of the program adjust.m.
EXAMPLE 23.2
Consider the following system of equations:
2 38 9 8 9
1:9 2:1 –5:7 0:0 0:0 > > Φ1 >
> >
> 0>>
6 2:1 3:4 1:5 >
> Φ2 >
> >
>0>
6 3:3 0:0 77>
< >
= >
< >
>
=
6 7
6 –5:7 1:5 2:2 4:5 2:8 7 Φ3 = 0 (E.1)
6 7> >
> > >
4 0:0 3:3 4:5 5:6 –1:8 5>
>
> Φ4 >
> >
>
>
>
>0>
>
>
: ; >
: > ;
0:0 0:0 2:8 –1:8 4:7 Φ5 0
! !
By renaming the characteristic matrix [A] as [GK] and the characteristic vector B as P , the arrays [GK]
!
and P can be identified from Eq. (E.1) as
2 3 8 9
1:9 2:1 –5:7 > 0>
>
> >
>
6 3:4 7 >
> >
>
6 1:5 3:3 7 >
< > 0 =
6 7 !
6
½GK = 6 2:2 7
4:5 2:8 7, P = 0
6 7 >
> >
>
>
> >
4 5:6 –1:8 0:0 5 >0>
> >
: > ;
4:7 0:0 0:0 0
with NN = 5 and NB = 3.
Modify the arrays GK and P to incorporate the boundary condition, Φ3 = Φ3 = 2:0:
CHAPTER 23
MATLAB Programs for Finite Element Analysis
Solution
The stated boundary condition gives II = 3 and CONST = 2.0. The main program, named
main_adjust.m, which calls the subprogram adjust.m as well as the results (modified arrays GK and P),
is shown below.
nn number of nodes
ne number of bar elements
nd number of degrees of freedom of the truss, including the fixed degrees of
freedom
nb bandwidth of the system stiffness matrix
nfix number of fixed degrees of freedom
e Young’s modulus
ifix degree of freedom numbers that are fixed
ifree number of free degrees of freedom; nfree = nd – nfix
loc nodal connectivity array of size ne × 2; loc (i, j) denotes the node number of end
j ( j = 1, 2) of bar element i (i = 1, 2, … , ne)
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
EXAMPLE 23.3
Find the deflections of nodes and the axial stresses developed in the space truss shown in Figure 21.8
under the following two load conditions:
Load condition 1: Non zero components of the load vector are p(2,1) = 88,960 N,
p(3,1) = –22,240 N, p(5,1) = –88,960 N, p(6,1) = –22,240 N
Load condition 2: Non zero components of the load vector are p1(1,1) = 4448 N,
p1(2,1) = 44,480 N, p1(3,1) = –22,240 N, p1(5,1) = 44,480 N, p1(6,1) = –22,240 N,
p1(7,1) = 2224 N, p1(16,1) = 2224 N
Other data are E = 6.9 × 1010 Pa, and area of cross-section = 1 mm2 for every bar element.
Solution
Each bar of the truss shown in Figure 21.8 is modeled as a bar element in 3D space. A main program,
688 called main_truss3D.m, is created to define the input data, call the program truss3D.m, and display
the results. A listing of the program main_truss3D.m and the results given by the program are shown
below.
[D,D1, st, st1]=truss3D (nn, ne, nd, nb, nfix, e, ifix, loc, x, y, z, A, p, p1);
fprintf (‘ \n’);
fprintf (‘ Load condition 2: \n’);
fprintf (‘ Nodeal displacements: \n’);
fprintf (‘Node X-disp Y-disp Z-disp\n’) ;
for i=1 : 6
fprintf (‘% 1d % 4.4e % 4.4e % 4.4e\n’,i,D1 (3*i−
2), D1 (3*i−1), D1 (3*i));
end
for i=7 : nn
fprintf (‘% 1d % 4.4e % 4.4e % 4.4e\n’, i, 0, 0, 0) ;
end
fprintf (‘ \n’);
fprintf (‘ Load condition 1: \n’);
fprintf (‘ Element Stress: \n’);
fprintf (‘ Element Axial stress \n’);
for i=1 : ne
fprintf (‘% 1d % 4.4e \n’, i, st (i)) ;
end
(Continued )
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
Load condition 1:
Nodeal displacements:
Node X-disp Y-disp Z-disp
1 −7.1742e−008 1.2450e−005 −8.8742e−007
2 7.1742e−008 −1.2450e−005 −8.8742e−007
3 2.9731e−006 −5.2279e−007 −2.2515e−006
4 2.9891e−006 5.7343e−007 1.1822e−006
5 −2.9731e−006 5.2279e−007 −2.2515e−006
6 −2.9891e−006 −5.7343e−007 1.1822e−006
7 0.0000e+000 0.0000e+000 0.0000e+000
8 0.0000e+000 0.0000e+000 0.0000e+000
9 0.0000e+000 0.0000e+000 0.0000e+000
10 0.0000e+000 0.0000e+000 0.0000e+000
Load condition 2:
Nodeal displacements:
Node X-disp Y-disp Z-disp
1 6.5910e−007 1.2726e−005 −6.8846e−007
690 2 7.5028e−007 1.2726e−005 −1.0704e−006
3 3.2594e−008 8.4982e−007 −3.1324e−006
4 2.1198e−007 8.7459e−007 −3.3721e−006
5 2.6689e−008 8.0020e−007 2.0590e−006
6 2.1789e−007 8.2497e−007 2.2987e−006
7 0.0000e+000 0.0000e+000 0.0000e+000
8 0.0000e+000 0.0000e+000 0.0000e+000
9 0.0000e+000 0.0000e+000 0.0000e+000
10 0.0000e+000 0.0000e+000 0.0000e+000
Load condition 1:
Element Stress:
Element Axial stress
1 5.1971e+003
2 −6.7431e+004
3 5.8388e+004
4 5.8388e+004
5 −6.7431e+004
6 6.7020e+004
7 −8.3372e+004
8 −8.3372e+004
9 6.7020e+004
10 1.8344e+003
11 1.8344e+003
12 5.7966e+002
13 5.7966e+002
14 −9.2069e+003
15 8.4817e+002
16 8.4817e+002
CHAPTER 23
MATLAB Programs for Finite Element Analysis
17 −9.2069e+003
18 4.0847e+004
19 −4.9780e+004
20 −4.9780e+004
21 4.0847e+004
22 −1.5928e+004
23 −1.0143e+003
24 −1.5928e+004
25 −1.0143e+003
Load condition 2:
Element Stress:
Element Axial stress
1 3.3027e+003
2 −3.3429e+004
3 −2.9559e+004
4 1.9943e+004
5 2.3812e+004
6 −5.1025e+004
7 3.1976e+004
8 −4.7858e+004
9 3.5143e+004
10 9.0003e+002
11 2.6945e+003
12 6.4976e+003
13 −6.9254e+003
14 −1.6090e+004
15 1.0767e+004
16 −1.9058e+004 691
17 7.7990e+003
18 −3.0030e+004
19 −3.0701e+004
20 2.1491e+004
21 2.0819e+004
22 4.4997e+004
23 −5.5561e+004
24 −6.1784e+004
25 3.8774e+004
EDU>>
CX,CY = vector arrays of size NN each. CX(I) and CY(I) denote the global X and Y
coordinates of node I.
E = Young’s modulus of the material.
ANU = Poisson’s ratio of the material.
T = thickness of the plate.
NFIX = number of fixed degrees of freedom (zero displacements).
IFIX = a vector array of sixe NFIX. IFIX(I) denotes the I-th fixed degree of freedom
number.
P = an array of size ND × M representing the global load vectors.
The array P returned from the program cst.m to the main program represents the global
displacement vectors with P(I, J ) denoting the I-th component of global load in input
(or displacement in output) vector in the J-th load condition.
The program cst.m requires the following subprograms: lambda.m, decomp.m, and solve.m.
The following example illustrates the application of the program cst.m.
EXAMPLE 23.4
Find the nodal deflections and element stresses in the plate under tension described in Section 10.3.1
and shown in Figure 10.4(a) using CST elements.
Solution
Due to the double symmetry of the plate and the loading, only a quadrant of the plate is used for
idealization. The finite element idealization and the node numbers used are indicated in Figure 10.4(b).
Two degrees of freedom are considered at each node as shown in Figure 10.4(c).
P(6, 1) = 1000.0 N
P(4, 1) = 2000.0 N
P(2, 1) = 1000.0 N
Note
The node numbering scheme used in Figure 10.4(b) leads to a high bandwidth (NB = 18). We can
reduce NB to 10 by relabeling the nodes 8, 9, 4, 7, 6, and 5 of Figure 10.4(b) as 4, 5, 6, 7, 8, and 9,
respectively.
A main program, called main_cst.m, is created to define the input data, call the program cst.m, and
display the results. A listing of the program main_cst.m and the results of the analysis are shown
below.
% Main_CST
% -------------------------------------------------
% Written by Singiresu S. Rao
% The Finite Element Method in Engineering
% -------------------------------------------------
NN = 9; % Input data
NE = 8;
ND = 18;
NB = 18;
CHAPTER 23
MATLAB Programs for Finite Element Analysis
NFIX = 6;
M = 1;
E = 2e6;
ANU = 0.1;
% output results
fprintf(‘ Nodal displacements: \n’);
fprintf(‘Node X–component Y–component\n’);
for i=1:NN
fprintf(‘%1d %6.4f %6.4f\n’, i, P(2*i–1), P(2*i));
end
fprintf(‘\n’);
fprintf(‘Stresses in elements:\n’);
fprintf(‘Element sigma xx sigma yy sigma xy\n’);
for i = 1:NE
fprintf(‘%1d %6.4f %6.4f % 6.4f\n’, i, STRES 693
(i, 1), STRES (i, 2), STRES (i, 3));
end
Nodal displacements:
Node X-component Y-component
1 –0.0020 0.0200
2 –0.0010 0.0200
3 –0.0000 0.0200
4 –0.0000 0.0100
5 –0.0000 0.0000
6 –0.0010 0.0000
7 –0.0020 0.0000
8 –0.0020 0.0100
9 –0.0010 0.0100
Stresses on elements:
Element sigma xx sigma yy sigma xy
1 0.0000 2000.0000 –0.0000
2 0.0000 2000.0000 –0.0000
3 –0.0000 2000.0000 0.0000
4 –0.0000 2000.0000 0.0000
5 –0.0000 2000.0000 0.0000
6 –0.0000 2000.0000 –0.0000
7 –0.0000 2000.0000 –0.0000
8 0.0000 2000.0000 –0.0000
The results given by the program cst.m can be seen to be identical to the results obtained with hand
computations (shown in Table 10.1).
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
CST elements with three degrees of freedom per node as shown in Figure 10.2 are
considered in the modeling. To illustrate the application of the program CST3D.m, the
following example is considered.
EXAMPLE 23.5
Find the nodal deflections and element stresses in the box-beam described in Section 10.3.3 and shown
in Figure 10.7 using CST elements.
Solution
The finite element idealization using CST elements is shown in Figure 10.8. A main program, called
main_cst3D.m, is created to define the input data, call the program cst3D.m, and display the results.
A listing of the program main_CST3D.m and the results of the analysis are shown below.
for ii=1:nelm;
tt (ii) = 1; % thickness
end
for ii= (nelm+1) :neltot;
tt(ii)= 1; % thickness
end
rho=0.28/384; % weight density (unit weight/gravitational constant)
nmode=3;
NB=4; % No. of elements near root (for stress)
%
% FF (i, 1) = Load applied along dof i (1 = load condition number)
% 695
% ---------------------------------------
% input data for nodal coordinates (only CST elements)
% ---------------------------------------
% model 1
% CX = X coordinates of all nodes
% CY = Y coordinates of all nodes
% CZ = Z coordinates of all nodes
CX=
[60, 60, 48, 48, 36, 36, 24, 24, 12, 12, 0, 0, 60, 60, 48, 48, 36, 36, 24, 24, 12, 12, 0, 0];
CY=[18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0];
CZ=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12];
%
% ----------------------------------------------------------------
% input data for nodal coordinates in vector from-------
% gcood = (X, Y, Z) coordinates of nodes 1, 2..., nnode
% ----------------------------------------------------------------
gcoord=[60 18 0;60 0 0;48 18 0;48 0 0;36 18 0;36 0 0;24 18 0;24 0 0;12
18 0;12 0 0;0 18 0;0 0 0;...
60 18 12;60 0 12;48 18 12;48 0 12;36 18 12;36 0 12;24 18 12;24 0
12; ...
12 18 12;12 0 12;0 18 12;0 0 12];
% ----------------------------------------------------------------
% input data for nodal connectivity for each element
% nodes (i, j), i=element no., j=global nodes of local corners 1, 2, 3 of
% elements 1, 2, ..., neltot
% ----------------------------------------------------------------
(Continued )
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
[disp, STRESS]=CST3D
(neltot, nelm, nemp, nels, nnel, ndof, nnode, sdof, effdof, topdof, edof, emodule, p
oisson, tt, ...
rho, nmode, NB, FF, CX, CY, CZ, gcoord, nodes, ISTRES, bcdof);
% ************************
% OUTPUT:=
fprintf (‘ Nodal displacements \n’);
fprintf (‘Node X-disp Y-disp Z-disp\n’);
for i=1:1:20
696 fprintf (‘%1d %6.8f %6.8f %6.8f\n’,
i, disp (3* (i–1)+1), disp (3*(i–1)+2), disp (3* (i–1)+3));
end
fprintf (‘ \n’);
Nodal displacements
Node X-disp Y-disp Z-disp
1 −0.00143909 0.00009891 −0.01149128
2 −0.00142851 0.00005433 −0.01128080
3 −0.00135326 0.00009942 −0.00824795
4 −0.00133865 0.00003701 −0.00805697
CHAPTER 23
MATLAB Programs for Finite Element Analysis
The results given by the program CST3D.m can be seen to be identical to the results shown in
Table 10.3.
697
23.6 TEMPERATURE DISTRIBUTION IN ONE-DIMENSIONAL FINS
To find the temperature distribution in a 1D fin (details given in Section 14.2), a program
called heat1.m is developed. The program requires the following quantities:
NN = number of nodes (input).
NE = number of elements (input).
NB = semibandwidth of the overall matrix GK (input).
IEND = 0: means no heat convection from free end.
IEND = any nonzero integer: means that heat convection occurs from the free end
(input).
CC = thermal conductivity of the material, k (input).
H = convection heat transfer coefficient, h (input).
TINF = atmospheric temperature, T∞ (input).
QD = strength of heat source, q (input).
Q = boundary heat flux, q (input).
NODE = array of size NE × 2; NODE(I, J) = global node number corresponding to J-th
(right-hand side) end of element I (input).
XC = array of size NN; XC(I) = x coordinate of node I (input).
A = array of size NE; A(I) = area of cross-section of element I (input).
PERI = array of size NE; PERI(I) = perimeter of element I (input).
TS = array of size NN; TS(I) = prescribed value of temperature of node I (input). If the
temperature of node I is not specified, then the value of TS(I) is to be given as 0.0.
The program heat1.m requires the following subprograms: adjust.m, decomp.m, and
solve.m.
The following example illustrates the use of the program heat1.f.
PART 7
ABAQUS and ANSYS Software and MATLAB®Programs for Finite Element Analysis
EXAMPLE 23.6
Find the temperature distribution in the 1D fin considered in Example 14.4 and shown in Figure 14.1
with two finite elements.
Solution
A main program called main_heat1.m is created for solving the problem. The listing of the program
main_heat1.m and the nodal temperatures given by the program are shown below. The results can be
seen to agree with the results obtained in Example 14.4 with hand computations.
Node Temperature
1 140.0000
2 80.4475
3 63.3226
The program radiat.m requires the following subprograms: adjust.m, decomp.m, and
solve.m.
The following example illustrates the use of the program radiat.f.
EXAMPLE 23.7
Find the temperature distribution in the 1D fin considered in Example 14.13 using one finite element.
Solution
A main program called main_radiat.m is created for solving the problem. The listing of the program
main_radiat.m and the nodal temperatures given by the program are given below. It can be seen that
the present results agree with those obtained in Example 14.13 using hand computations.
EXAMPLE 23.8
Find the temperature distribution in the square plate with uniform heat generation considered in
Example 15.2 using triangular finite elements.
Solution
A main program called main_heat2.m is created for solving the problem. The listing of the program
main_ heat2.m and the nodal temperatures given by the program are shown below.
The results can be seen to be identical to those obtained in Example 15.2 using hand computations.
CHAPTER 23
MATLAB Programs for Finite Element Analysis
EXAMPLE 23.9
Find the potential function distribution in the confined flow around a cylinder considered in Example
18.4 using triangular finite elements.
Solution
A main program called main_phiflo.m is created for solving the problem. The listing of the program
main_phiflo.m and the nodal values of potential function given by the program are shown below.
EXAMPLE 23.10
Find the stresses developed in prismatic shaft with a 4 cm × 4 cm cross-section that is subjected to a twist of
2 degrees per meter length using triangular finite elements. This example is the same as Example 20.1.
Solution
A main program called main_torson.m is created for solving the problem. The listing of the program
main_torson.m, the nodal values of stress function, and the shear stresses developed in the elements
given by the program are shown below.
PROBLEMS
23.1 Solve Problem 7.11 using the MATLAB program choleski.m.
23.2 Modify the matrix and the right hand side vector considered in Problem 6.22 to incorporate the boundary
conditions T5 = T6 = 50°C. Use the MATLAB program adjust.m.
23.3 Find the nodal displacements and element stresses in the truss considered in Problem 9.7 and Figure 9.18
using the MATLAB program truss3D.m.
23.4 Find the stresses developed in the plate shown in Figure 10.16 using at least 10 CST elements. Use the
MATLAB program cst.m.
23.5 Find the nodal displacements and element stresses developed in the box beam described in Section 10.3.3
and Figure 10.7 using the finite element model shown in Figure 10.8. Use the MATLAB program CST3D.m.
23.6 Solve Problem 14.8 using the MATLAB program heat1.m.
23.7 Solve Problem 14.8 by including radiation heat transfer from the lateral and end surfaces of the fin using the
MATLAB program radiat.m. Assume ε = 0.1.