Page 114 -
P. 114
elseif rem(k,2)==0
w(k)=4;
else
w(k)=2;
end
end
Intsimp=((b-a)/(3*(length(x)-1)))*sum(y.*w)
Now compare the above answer with the one you obtain if you use the Trap-
ezoid rule, by entering the command: Inttrapz=trapz(x,y).
In-Class Exercise
Pb. 4.33 In the above derivation of Simpson’s method, we constructed the
algorithm by determining the weights sequence. Reformulate this algorithm
into an equivalent iterator format.
Homework Problems
In this chapter, we surveyed three numerical techniques for computing the
integral of a function. We observed that the different methods lead to differ-
ent levels of accuracy. In Section 6.8, we derive formulas for estimating the
accuracy of the different methods discussed here. However, and as noted pre-
viously, more accurate techniques than those presented here exist for calcu-
lating integrals numerically; many of these are in the MATLAB library and
are covered in numerical analysis courses. In particular, familiarize yourself,
using the help folder, with the commands quad and quad8.
Pb. 4.34 The goal of this problem, using the quad8 command, is to develop
a function M-file for the Gaussian distribution function of probability theory.
The Gaussian probability density function is given by:
2
fx() = 1 exp − x ( − a )
X
X (2π ) / 12 σ 2σ 2
X X
where –∞ < a < ∞, 0 < σ are constants, and are equal to the mean and the
X
X
square root of the variance of x, respectively.
The Gaussian probability distribution function is defined as:
Fx() ≡ ∫ x f ( )ζζ
d
X −∞ X
© 2001 by CRC Press LLC