Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...
Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...
Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
8.4. GAUSSIAN QUADRATURE 113<br />
function iappx = gaussComp(f,a,b,n)<br />
% code to approximate integral of f over n equal subintervals of [a,b]<br />
x = a .+ (b-a) .* (0:n) ./ n;<br />
iappx = 0;<br />
for i=1:n<br />
iappx += gauss2(f,x(i),x(i+1));<br />
end<br />
Use your code to approximate the error function:<br />
erf(z) = 2 √ π<br />
∫ z<br />
0<br />
e −t2 dt.<br />
Compare your results with the octave/Matlab builtin function erf. (Try help erf in octave,<br />
or see http://mathworld.wolfram.com/Erf.html)<br />
The error function is used in probability. In particular, the probability that a normal random<br />
variable is within z standard deviations from its mean is<br />
erf(z/ √ 2)<br />
Thus erf(1/ √ 2) ≈ 0.683, and erf(2/ √ 2) ≈ 0.955. These numbers should look familiar to you.