2
______________________________________________________________________________
2.25 Write a user-defined MATLAB function that evaluates the definite integral of a function by
using the Riemann sum (see Eq. (2.7)). For function name and arguments, use I=Rie-
mannSum(Fun,a,b). Fun is a name for the function that calculates the value of for a given value
of x. It is a dummy name for the function that is imported into RiemannSum. a and b are the limits of
integration, and I is the value of the integral. The Riemann sum is calculated by dividing the integration
interval into ten subintervals. Use RiemannSum for evaluating the definite integral . Com-
pare the result with the exact value of the integral, 1.
Solution
fx()
fx()
ab,[]
xexxd
0
1
1
2.26 Write a user-defined MATLAB function that carries out multiplication of two matrices
. For function name and arguments, use C = MatrixMult(A,B). The input arguments A
and B are the matrices to be multiplied. The output argument C is the result. Do not use the matrix multipli-
cation of MATLAB. The function MatrixMult should first check if the two matrices can be multiplied,
and if not, the output C should be the message “The matrices cannot be multiplied since the number of
rows in [b] is not equal to the number of columns in [a].” Use MatrixMult to carry out the multiplica-
tion that is illustrated in Fig. 2.14.
Solution
The following MATLAB user-defined function solves this problem:
function C = MatrixMult(A,B)
c[] a[]b[]=
1
2.27 Write a user-defined MATLAB function that determines the cross product of two vectors
. For the function name and arguments, use W = Cross(V,U). The input arguments V and U
are the vectors to be multiplied. The output argument W is the result (three-element vector).
(a)Use Cross to determine the cross product of the vectors and .
(b)Use Cross to determine the cross product of the vectors and .
Solution
The following user-defined function solves this problem:
function W = Cross(V,U)
W(1)=V(2)*U(3)-V(3)*U(2);
WVU=
vi2j3k++=
v2ij3k+=
uijk++=
1
2.28 Write a user-defined MATLAB function that determines the dot product of two vectors .
For function name and arguments, use W = DotPro(V,U). The input arguments V and U are the vectors
to be multiplied. The output argument W is the result (a scalar).
(a)Use DotPro to determine the cross product of the vectors and .
(b)Use DotPro to determine the cross product of the vectors and .
Solution
WVU=
vi2j3k++=
u3i2jk++=
v2ij3k+=
uijk++=
1
2.29 Write a user-defined MATLAB function to unfurl an matrix into a vector of size . The
vector consists of the matrix rows in order. For example, if the matrix is: , then the vector is:
. For the function name and arguments, use v=unfurl(A), where the
input argument A is a matrix of any size, and the output argument v is the vector.
Use the function (in the Command Window) to unfurl the matrix:
Solution
The listing of the user defined function unfurl is:
function V=unfurl(A)
mn×
1mn×
a11 a12 a13
a21 a22 a23
a31 a32 a33
a11 a12 a13 a21 a22 a23 a31 a32 a33
94 6 10 4
2516 0
1211 0 3 7
1
2.30 Write a user-defined MATLAB function that determines the transpose of any size matrix. Do
not use the MATLAB built-in command for the transpose. For the function name and arguments, use
At=transp(A), where the input argument A is a matrix of any size, and the output argument At is the
transpose of A.
Use the function (in the Command Window) to determine the transpose of the matrix:
Solution
The listing of the user-defined function transp is:
function At=transp(A)
mn×
214 2
342 1
35 21
2.31 Write a user-defined MATLAB function that calculates the determinant of a square matrix,
where n can be 2, 3, or 4. For function name and arguments, use D = Determinant(A). The input argu-
ment A is the matrix whose determinant is calculated. The function Determinant should first check if
the matrix is square. If it is not, the output D should be the message “The matrix must be square.”
Use Determinant to calculate the determinant of the following two matrices:
(a) . (b) .
Solution
The following three user-defined function det2by2, det3by3, and det4by4 are written:
function D = Determinant(A)
% The function calculates the determinant of a n by n matrix,
nn×()
154
236
111
1234
5678
9 101112
13 14 15 16
% The function calculates the determinant of a 4 by 4 matrix.
Sa=A(2:4,2:4);
Sb=A(2:4,[1 3 4]);
Sc=A(2:4,[1 2 4]);
Sd=A(2:4,1:3);
D3=A(1,1)*det3by3(Sa)-A(1,2)*det3by3(Sb)+A(1,3)*det3by3(Sc)-
A(1,4)*det3by3(Sd);
The user-defined function Determinant is used in the Command Window for determining the determi-
nants in parts (a) and (b).
2.32 One important application involving the total differential of a function of several variables is estima-
tion of uncertainty.
(a) The electrical power P dissipated by a resistance R is related to the voltage V and resistance by
. Write the total differential dP in terms of the differentials dV and dR, using Eq. (2.63).
(b)dP is interpreted as the uncertainty in the power, dV as the uncertainty in the voltage, and dR as the
uncertainty in the resistance. Using the answer of part (a), determine the maximum percent uncertainty
in the power P for V with an uncertainty of 2%, and with an uncertainty of 3%.
Solution
(a) Using Eq.(2.63),
PV2
R
—–=
V400=
R1000 Ω=
dP P
V
—— dV P
R
—— dR+2V
R
——dV V2
R2
—–dR+==
2.33 The dimensions of a rectangular box are measured to be 10 cm x 20 cm x 15 cm, and the error in
measuring each length is mm. What is the error in the total volume of the box if the error in measuring
each length is the differential corresponding to that coordinate?
Solution
1±
2.34 An aircraft begins its descent at a distance
( is the spot at which the plane touches down) and an
altitude of H. Suppose a cubic polynomial of the following
form is used to describe the landing:
where y is the altitude and x is the horizontal distance to the
aircraft. The aircraft begins its descent from a level position,
and lands at a level position.
(a) Solve for the coefficients a, b, c, and d.
(b) If the aircraft maintains a constant forward speed ( ) and the magnitude of the verti-
cal acceleration ( ) is not to exceed a constant A, show that .
(c) If ft/s2, ft, and mph, how far from the airport should the pilot begin the
descent?
Solution
(a) Since the origin is at the point of landing, when . This means that . Since the air-
craft begins its descent from a level position and lands at a level position, and .
This means that and , or . With these determinations, the polynomial
that describes the landing becomes:
xL=
x0=
yax
3bx2cx d+++=
dx
dt
—–uconsttan==
d2y
dt2
——-
6Hu2
L2
————A
A0.3=
H15000=
u200=
y0=
x0=
d0=
dy
dx
—–
x0=
0=
dy
dx
—–
xL=
0=
c0=
3aL22bL+0=
b3
2
aL=
dx
2.35 An artery that branches from another more major
artery has a resistance for blood flow that is given by:
where is the resistance to blood flow from the major
to the branching artery along path ABC (see diagram), d is
the diameter of the smaller, branching artery, D is the diam-
eter of the major artery, is the angle that the branching
vessel makes with the horizontal, or axis, of the major artery,
and L and H are the distances shown in the figure.
(a) Find the angle θ that minimizes the flow resistance in terms of d and D.
(b) If , and mm, what is the value of d that minimizes the resistance to blood flow?
Solution
(a)
is given as a function of . To minimize , set . This yields:
Rflow KLH θcot
D4
—————–——-Hθcsc
d4
—————+
⎝⎠
⎛⎞
=
Rflow
θ
θ45°=
D5=
Rflow
θ
Rflow
Rflow
∂θ
————–-0=
Rflow
∂θ
————–KH
D4
——-d
dθ
—–1
θtan
———-
⎝⎠
⎛⎞
KH
d4
——-d
dθ
—–1
θsin
———-
⎝⎠
⎛⎞
+KH
D4
——-1
sin2θ
———–KH
d4
——-θcos
sin2θ
———–
0===
θ
θ
θ