0% found this document useful (0 votes)
5 views

Appendix D MATLAB® Files

The document provides MATLAB® functions and scripts used for solving engineering problems, including stress invariants, cantilever beam displacement, and stress-strain relationships. It includes detailed descriptions of various functions, their inputs, and outputs, as well as how to obtain the associated m-files. Additionally, it offers guidance on using these functions for specific engineering applications.

Uploaded by

friend good
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Appendix D MATLAB® Files

The document provides MATLAB® functions and scripts used for solving engineering problems, including stress invariants, cantilever beam displacement, and stress-strain relationships. It includes detailed descriptions of various functions, their inputs, and outputs, as well as how to obtain the associated m-files. Additionally, it offers guidance on using these functions for specific engineering applications.

Uploaded by

friend good
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

APPENDIX D

MATLAB® Files

At various points in this book, MATLAB® functions or scripts are used to aid in the
solution process. The listings of the m-files for those functions or scripts are given below.
[Note: because of formatting changes, there may be some minor differences between these
listings and the actual m-files.] The m-files can be obtained from Cambridge University Press
at www.cambridge.org/schmerr or by sending an e-mail with the subject title “Advanced
Mechanics Codes” to the author at [email protected]
stress_invs

function [I1, I2, I3] = stress_invs(s)


% [I1, I2, I3] =stress_invs(s) uses the stress matrix s as its
% input argument and returns the three stress invariants (I1,
% I2, I3)
I1 = trace(s);
I2 = s(1,1)*s(2,2) - s(1,2)^2 + s(1,1)*s(3,3) - s(1,3)^2 ...
+ s(2,2)*s(3,3) - s(2,3)^2;
I3 = det(s);

cantilever_d

%script cantilever_d
% This script plots the 2-d displacement field of a cantilever
% beam from engineering beam theory
% make an 8x4 grid on a beam with normalized length and width
% of 1 and 0.2, respectively.
xn = linspace(0,1,8);
yn = linspace (-0.1, 0.1, 4);
[x,y] = meshgrid(xn, yn);
% choose values for Poisson’s ratio and normalized height hn =
% h/L
nu = 1/3;
hn = 0.1;

557

ISTUDY
558 Appendix D

% calculate normalized beam displacements

ux = x.^2.*y/2 + (1+nu)*(hn*y - y.^3/3) + nu*y.^3/6 -y/2;


uy = -x.^3/6 - nu*x.*y.^2/2 + x/2 -1/3;
% make a quiver plot of the displacements
quiver(x, y, ux, uy)
axis equal

stress_strain

function stress = stress_strain(E, nu, strain)


% stress = stress_strain(E, nu, strain) has as inputs Young’s
% modulus, E,(in GPa), Poisson’s ratio, nu, and the tensor
% strain matrix, strain, (in micro strain). The function
% calculates the stress matrix (in MPa) for an isotropic
% elastic solid

E = E*10^3; % put E in MPa


e = strain*10^(-6); % put micro factor in strain
C = E/((1+nu)*(1-2*nu));
G = E/(2*(1+nu));
stress = zeros(3,3);
stress(1,1) = C*((1-nu)*e(1,1) +nu*(e(2,2) +e(3,3)));
stress(2,2) = C*((1-nu)*e(2,2) +nu*(e(1,1) +e(3,3)));
stress(3,3) = C*((1-nu)*e(3,3) +nu*(e(1,1) +e(2,2)));
stress(1,2) = 2*G*e(1,2);
stress(1,3) = 2*G*e(1,3);
stress(2,3) = 2*G*e(2,3);
% make stresses symmetric
stress(2,1) = stress(1,2);
stress(3,1) = stress(1,3);
stress(3,2) = stress(2,3);

strain_stress

function strain = strain_stress(E, nu, stress)


% strain = strain_stress( E, nu ,stress) returns the strain
% matrix strain, measured in microstrain, for a state of
% stress, stress, with the stresses measured in MPa, and where
% E is given in GPa. nu is Poisson’s ratio.
% To get strains in microstrain, multiply E by 10^-3

ISTUDY
MATLAB® Files 559

E = E*10^-3;
G = E/(2*(1+nu));
strain(1,1) = (1/E)*(stress(1,1) -nu*(stress(2,2). . . +stress(3,3)));
strain(2,2) = (1/E)*(stress(2,2) -nu*(stress(1,1). . . +stress(3,3)));
strain(3,3) = (1/E)*(stress(3,3) -nu*(stress(1,1). . . +stress(2,2)));
strain(1,2) = stress(1,2)/(2*G); % note: these are tensor
% strains
strain(1,3) = stress(1,3)/(2*G);
strain(2,3) = stress(2,3)/(2*G);
strain(2,1) = strain(1,2);
strain(3,1) = strain(1,3);
strain(3,2) = strain(2,3);

M_Matrix

function M = M_Matrix(l)
% M = M_Matrix(l) takes as its input argument the direction
% cosine matrix l whose transpose, lt, transforms the x-
% coordinates to the x’-coordinates through the relation {x’}
% = [lt]{x}. The function returns the 6x6 matrix, M, which
% transforms the 6x6 matrix of elastic constants,C, as
% measured in the x-coordinates, to the matrix of elastic
% constants,C’, as measured in the x’-coordinates, through the
% relation [C’] = [M][C][Mt], where Mt is the transpose of M.

M = zeros(6,6);
M(1,1) = l(1,1)^2;
M(1,2) = l(2,1)^2;
M(1,3) = l(3,1)^2;
M(1,4) = 2*l(2,1)*l(3,1);
M(1,5) = 2*l(3,1)*l(1,1);
M(1,6) = 2*l(2,1)*l(1,1);
M(2,1) = l(1,2)^2;
M(2,2) = l(2,2)^2;
M(2,3) = l(3,2)^2;
M(2,4) = 2*l(2,2)*l(3,2);
M(2,5) = 2*l(1,2)*l(3,2);
M(2,6) = 2*l(1,2)*l(2,2);
M(3,1) = l(1,3)^2;
M(3,2) = l(2,3)^2;
M(3,3) = l(3,3)^2;
M(3,4) = 2*l(2,3)*l(3,3);

ISTUDY
560 Appendix D

M(3,5) = 2*l(1,3)*l(3,3);
M(3,6) = 2*l(1,3)*l(2,3);
M(4,1) = l(1,2)*l(1,3);
M(4,2) = l(2,2)*l(2,3);
M(4,3) = l(3,2)*l(3,3);
M(4,4) = l(2,2)*l(3,3) + l(3,2)*l(2,3);
M(4,5) = l(1,2)*l(3,3) + l(3,2)*l(1,3);
M(4,6) = l(1,2)*l(2,3) + l(2,2)*l(1,3);
M(5,1) = l(1,1)*l(1,3);
M(5,2) = l(2,1)*l(2,3);
M(5,3) = l(3,1)*l(3,3);
M(5,4) = l(2,1)*l(3,3) + l(3,1)*l(2,3);
M(5,5) = l(1,1)*l(3,3) + l(3,1)*l(1,3);
M(5,6) = l(1,1)*l(2,3) + l(2,1)*l(1,3);
M(6,1) = l(1,1)*l(1,2);
M(6,2) = l(2,1)*l(2,2);
M(6,3) = l(3,1)*l(3,2);
M(6,4) = l(2,1)*l(3,2) + l(3,1)*l(2,2);
M(6,5) = l(1,1)*l(3,2) + l(3,1)*l(1,2);
M(6,6) = l(1,1)*l(2,2) + l(2,1)*l(1,2);

m_to_v

function y = m_to_v(input, type)


% m_to_v converts a 3x3 matrix of strains or stresses to a 6x1
% vector
% first input argument is the 3x3 matrix
% the type argument is either ’strain’ or ’stress’
% if type = ’strain’ then the matrix shear strains are doubled
% to give engineering shear strains
if strcmp(type, ’stress’)
y(1) = input(1,1);
y(2) = input(2,2);
y(3) = input(3,3);
y(4) = input(2,3);
y(5) = input(1,3);
y(6) = input(1,2);
elseif strcmp(type, ’strain’)
y(1) = input(1,1);
y(2) = input(2,2);
y(3) = input(3,3);

ISTUDY
MATLAB® Files 561

y(4) = 2*input(2,3);
y(5) = 2*input(1,3);
y(6) = 2*input(1,2);
else
error(’wrong type’)
end
% put in column vector
y = y’;

v_to_m

function y = v_to_m(input, type)


% v_to_m converts a 6x1 vector of strains or stresses to a 3x3
% matrix
% first input argument is the 6x1 vector
% the type argument is either ’strain’ or ’stress’
% if type = ’strain’ then the vector engineering shear strains
% are halved to generate the tensor shear strains in the 3x3
% matrix
if strcmp(type, ’stress’)
y(1,1) = input(1);
y(2,2) = input(2);
y(3,3) = input(3);
y(2,3) = input(4);
y(1,3) = input(5);
y(1,2) = input(6);
elseif strcmp(type, ’strain’)
y(1,1) = input(1);
y(2,2) = input(2);
y(3,3) = input(3);
y(2,3) = input(4)/2;
y(1,3) = input(5)/2;
y(1,2) = input(6)/2;
else
error(’wrong type’)
end
y(2,1) = y(1,2);
y(3,1) = y(1,3);
y(3,2) = y(2,3);

ISTUDY
562 Appendix D

rosette

function [exx, eyy, exy] = rosette(anga, angb, angc, ea, eb,. . . ec)
% [exx, eyy, exy] = rosette(anga, angb, angc, ea, eb, ec)
% takes the three angles (anga, angb, angc) of the three gages
% in a rosette gage (as measured in degrees from the x-
% axis)and the three strains (ea, eb, ec)measured by those
% gages, and returns the tensor strains(exx, eyy, exy)
nax = cos(anga*pi/180);
nay = sin(anga*pi/180);
nbx = cos(angb*pi/180);
nby = sin(angb*pi/180);
ncx = cos(angc*pi/180);
ncy = sin(angc*pi/180);
Coeff = [ nax^2 nay^2 2*nax*nay;...
nbx^2 nby^2 2*nbx*nby; ...
ncx^2 ncy^2 2*ncx*ncy];
vals = [ ea eb ec]’;
strains = Coeff\vals;
exx = strains(1);
eyy = strains(2);
exy = strains(3);

stress_singularity

function stress_singularity()
% stress_singularity determines the singular behavior of the
% stresses near a sharp notch and plots the behavior of the
% parameter that controls the order of the singularity as a
% function of the notch angle.
warning off
a = linspace(0, pi, 100); %angle alpha
out = zeros (1,100);
for k =1:100
val = 0.5 +0.5*a(k)/pi; % choose initial guesses
out(k) = fzero(@singularity, val, [ ],a(k)); % find roots
end
plot((180/pi)*a(1:100), out(1:100))
axis([ 0 180 0 1.0])
xlabel(’\alpha , degrees’)

ISTUDY
MATLAB® Files 563

ylabel(’smallest root, m’)


warning on
function y = singularity(x, a)
y = sin (x*(2*pi-a)) - x*sin(a);
end
end

cross_section

function [Yct, Zct, Iy, Iz, Iyz] = cross_section( Ly, Lz,. . .


Yc, Zc)
% [Yct, Zct, Iy, Iz, Iyz] = cross_section(Ly, Lz, Yc, Zc)
% determines the coordinates of the centroid of a cross-
% section and the area moments relative to that centroid for a
% cross-section composed of rectangular parts. Ly and Lz are
% vectors containing the lengths of the rectangles in the Y-
% and Z-directions, and Yc, Zc are vectors containing the
% locations of the Y- and Z-coordinates of the rectangles. The
% outputs are the Y- and Z-coordinates of the cross-section
% centroid (Yct, Zct) and the area moments (Iy, Iz, Iyz)
% relative a set of centroidal (y,z) axes. Note that the
% rectangles must lie parallel to the (Y,Z) axes.
A = sum(Ly.*Lz); % total area of cross-section
% calculate location of centroid for the total cross-section
Yct = sum((Yc.*Ly.*Lz)/A); % Y-coordinate of centroid in (Y,Z)
Zct = sum((Zc.*Ly.*Lz)/A); % Z-coordinate of centroid in (Y,Z)
% calculate area moments about the (Y,Z) axes
IY = sum(Ly.*(Lz.^3)/12 +Ly.*Lz.*(Zc.^2)); % IYY in (Y,Z)
% coordinates
IZ = sum(Lz.*(Ly.^3)/12 +Ly.*Lz.*(Yc.^2)); % IZZ in (Y,Z)
% coordinates
IYZ = sum(Ly.*Lz.*Yc.*Zc); % IYZ in (Y,Z) coordinates
% use parallel axis theorem to calculate area moments about
% centroidal coordinates (y,z)
Iy = IY - A*(Zct^2); % Iyy for centroidal (y,z) axes
Iz = IZ -A*(Yct^2); % Izz for centroidal (y,z) axes
Iyz =IYZ - A*Yct*Zct; % Iyz for centroidal (y,z) axes

ISTUDY
564 Appendix D

sections

% script sections
% This script computes the location of the centroid and area
% moments for a L-section, a T-section, a J-section, a Z-
% section, and a I-section. In the command window one must
% enter a string ’L’, ’T’, ’J’, ’Z’, or ’L’ in a variable
% named type and then enter the lengths b, h, c and the
% thicknesses t1, t2, t3 (or a subset of these values) in the
% command window and then run this script. The script uses the
% function cross_section to return the location of the
% centroid and the area moments
switch type
case{’L’}
Ly(1) = b- t2; Ly(2) = t2;
Lz(1) = t1; Lz(2) = h;
Yc(1) = t2 + (b-t2)/2; Yc(2) =t2/2;
Zc(1) = t1/2; Zc(2) = h/2;
case{’T’}
Ly(1) = b; Ly(2) = t2;
Lz(1) = t1; Lz(2) = h-t1;
Yc(1) = 0; Yc(2) = 0;
Zc(1) = t1/2; Zc(2) = t1 + (h- t1)/2;
case{’J’}
Ly(1) = b -t2; Ly(2) = t2; Ly(3) = c-t2;
Lz(1) = t1; Lz(2) = h; Lz(3) = t3;
Yc(1) = t2 + (b-t2)/2; Yc(2) = t2/2; Yc(3) = t2 . . .
+(c-t2)/2;
Zc(1) = t1/2; Zc(2) = h/2; Zc(3) = h - t3/2;
case{’Z’}
Ly(1) = b - t2; Ly(2) = t2; Ly(3) = c -t2;
Lz(1) = t1; Lz(2) = h; Lz(3) = t3;
Yc(1) = t2 + (b-t2)/2; Yc(2) = t2/2; Yc(3) = -(c-t2)/2;
Zc(1) = t1/2; Zc(2) = h/2; Zc(3) = h -t3/2;
case{’I’}
Ly(1) = b; Ly(2) = t2; Ly(3) = c;
Lz(1) = t1; Lz(2) = h - t1 -t3; Lz(3) = t3;
Yc(1) = 0; Yc(2) = 0; Yc(3) = 0;
Zc(1) = t1/2; Zc(2) = t1 + (h -t1 -t3)/2;Zc(3) = . . .
h -t3/2;
otherwise
disp([’Unknown type’])
end
[yc, zc, Iy, Iz, Iyz] = cross_section(Ly, Lz, Yc, Zc)
ISTUDY
Index

Airy stress function, 149, 153, 190 direction cosine matrix, 35 Gauss’s theorem, 70
Airy stress function, Cartesian distortional strain energy density, 232 Gauss’s theorem -2D, 76
coordinates, 191 dummy load, 261 generalized displacements, 174
Airy stress function, polar coordinates, generalized forces, 174
197 eddy current NDE, 513 generalized Hooke’s law, 119
alternating stress, 502 effective maximum radius, 414 generalized strains, 174
effective polar area moment, 414, 527 Gerber curve, 504
Beltrami–Michell compatibility effective stress, 61, 500 Goodman curve, 504
equations, 149, 539 eigenvalue problem, 44 governing equations, 146
bending moment, 6 eigenvalues, 44
Betti–Rayleigh theorem, see reciprocal eigenvectors, 44 Hertz contact theory, 212
theorem of Betti–Rayleigh elastic bodies in contact, see Hertz Hooke’s law, 5
biaxial state of stress, 51 contact theory
bifurcation instability, 517 elastic constants, 122 interference, 188
biharmonic equation, 158 Engesser’s first theorem, 260 isotropic material, 119, 127
biharmonic equation, Cartesian Engesser’s second theorem, 264
coordinates, 191 engineering beam theory, 9 Kronecker delta, 35
biharmonic equation, polar coordinates, engineering shear strain, 14, 90
197 equilibrium equations, Cartesian Lamé constants, 148
biharmonic operator, 153 coordinates, 71 Laplace’s equation, 412
bimoment, 490 equilibrium equations, cylindrical limit-load instability, 517
boundary conditions, 158 coordinates, 82 local average rotation, 94
boundary element method, 148, 361 equilibrium equations, plane strain,
buckling, 515 154 maximum distortional strain energy
equilibrium equations, plane stress, 84 theory, 499
Castigliano’s first theorem, 256 equilibrium equations, spherical maximum normal stress theory,
Castigliano’s second theorem, 260 coordinates, 83 496
center of twist, 433 equivalent stress, 61 maximum shearing stress theory,
centroid, 527, 540 Euler buckling load, see critical buckling 497
Clapeyron’s theorem, 229 load Maxwell stress function, 149
combined bending and torsion, thin, mean stress, 502
closed sections, 477 fatigue failure, 502 membrane analogy, 423
combined bending and torsion, thin, fatigue strength, 504 Michell solutions, 197
open sections, 475 finite differences method, 148 Miner rule, see Palmgren-Miner rule
compatibility equations, 101, 303 first area moments, 527, 540 mixed second area moment, 8, 527, 540
compatibility matrix, 304, 312 first sectorial moment, 542 modified sectorial area function, 459
complementary strain energy density, flexibility matrix, 299 modified warping constant, 462
233 flexure stress, unsymmetrical bending, Mohr’s circle, 53
compliance matrix, 124 375 moment–curvature relationship, 8
concentrated force on a planar surface, force-based finite element method, axial Morera stress function, 149
209 loads, 295 Morrow curve, 504
concentrated force on a wedge, 208 force-based finite element method, beam
configuration factor, 509 bending, 329 Navier’s equations, 147, 310
constant life curves, 503 force-based finite element method, Navier’s table problem, 166
critical buckling load, 516 general body, 358 Neumann problem, 435
critical flaw size, 511 force-based finite element method, neutral axis, 7
cubic material, 127 specified displacements, 347 nonuniform torsion, 427
curved beam, 202 four pillars, 18 normal strain, 3, 88
fracture mechanics, 508 normal stress, 4, 32
deviatoric stress, 67 fracture toughness, 510 normalized Prandtl stress function, 419
dilatation, 98 fundamental solutions, 362 null space, 314

565

ISTUDY
566 Index

octahedral plane, 60 rosette strain gage, see strain gage strain invariants, 95
orthogonal matrix, 37 rosette strain transformation equations, 95
orthotropic material, 124 row-reduced echelon form, 313 strain–displacement relations, 91
strains, cylindrical coordinates, 112
Palmgren–Miner rule, 507 Saint-Venant torsional theory, see stress concentration at a circular hole,
parallel axis theorem, 531 uniform torsion 198
Paris law, 512 Saint-Venant’s principle, 161 stress intensity factor, 509
plane strain, 154 second area moments, 8, 527, 540 stress invariants, 43
plane stress, 51, 73 secondary twisting moment, 436 stress range, 502
planes of extreme shear stress, 56 secondary warping, 428 stress singularities, 214
Poisson’s equation, 418 sectorial area function, 391, 540 stress transformation equations, 34
Poisson’s ratio, 3 sectorial area origin, 541 stress vector, 28
polar area moment, 15, 540 sectorial area pole, 541
Prandtl stress function, 149, 417 sectorial products of areas, 527, 542 tensor shear strain, 90
primary twisting moment, 436 sectorial second moment, see warping theorem of minimum potential energy,
primary warping function, 428 constant 242
principal area moments, 531 shape functions, 281 thick-wall pressure vessel, 183
principal directions, 42 shear stress, 30 total shear stress, 32
principal origin, 549 shear center, 389 traction vector, see stress vector
principal planes, 42 shear flow, 17, 385 transformation of elastic constants, 132
principal pole, 545 shear flow expression, unsymmetrical transversely isotropic material, 126
principal sectorial area function, 527, bending, 386 Tresca theory, see maximum shearing
543 shear force, 9 stress theory
principal strains, 95 shear modulus, 14 true stress, 504
principal stresses, 42 shear strain, 89
principle of complementary virtual shear stress, 9 ultimate stress, 504
work, 250 shrink-fit, 187 ultrasonic NDE, 513
principle of complementary virtual work single plane of loading, 376 uniform torsion, 411
- axial loads, 280 single-valued displacement, 103 uniqueness, 243
principle of complementary virtual work singularity functions, 20 unit load method, 262
- beam bending, 319 S–N curve, 502
principle of least work, 264 snap-through buckling, 517 virtual displacements, 239
principle of minimum complementary Soderberg curve, 504 virtual work, 240
potential energy, 251 Somigliana’s identity, 364 Voigt notation, 124
principle of virtual work, 240 state of strain, 93 von Mises failure theory, 499
principle of virtual work, axial loads, state of stress, 29 von Mises stress, 61, 500
278 stiffness matrix, 148, 283
principle of virtual work, beam bending, stiffness-based finite element method, warping constant, 432, 527
316 148 warping constant, thin sections, 447
proper orthogonal matrix, 37 stiffness-based finite element method, warping function, 411
pseudostiffness matrix, 311, 333 axial loads, 281 warping normal stress, 428
pure bending of a curved beam, 202 stiffness-based finite element method, work, 224
beam bending, 320
Rayleigh–Ritz method, 257 stiffness-based finite element method, X-ray NDE, 514
reciprocal theorem of Betti–Rayleigh, general body, 356
268 strain energy, 226 yield normal stress, 498
reciprocity, 267 strain energy density, 226 yield shear stress, 497
redundants, 263 strain gage rosette, 141 Young’s modulus, 5

ISTUDY

You might also like