diary probA11.txt
echo on

% Problem 11

% Clear variables and declare x to be symbolic.

clear
syms x

% a)

% This is an integral that MATLAB couldn't perform symbolically in the
% previous problem.  We force the integral to be computed numerically
% using double.

double(int(exp(cos(x)), 0, pi))
% Since the interval we integrated over has length pi, our answer
% implies that the average value of exp(cos(x)) over the interval is
% about 3.9775/pi, or a little over 1.  This seems reasonable, since
% exp(cos(x)) varies from e to 1/e over the interval.

% b)

% MATLAB couldn't do the indefinite integral symbolically, but it
% can do the definite integral:

int(sqrt(x^4 + 1), 0, 1)
% The answer is very ugly though, and involves an elliptic function.
% It is more enlightening in this case to find a numerical value for
% the integral.

double(ans)
% This seems a bit low at first, since the integrand varies from 1 to
% 2 over an interval of length 1.  However, the integrand is close to
% 1 over most of the interval, for instance at x = 1/2 it is
% sqrt(1 + 1/16).  So, an average value of 1.0894 sounds reasonable.

% c)

% In the previous problem we saw that MATLAB evaluates this integral
% symbolically as the square root of pi.  So, the command below will
% merely evaluate the square root of pi as a double precision floating
% point number.

double(int(exp(-x^2), -inf, inf))
% Now let's compare to the square root of pi, using vpa to evaluate
% this number more accurately than double.

vpa('sqrt(pi)') - ans
% As expected, the difference is very small, roughly the amount of
% round-off error inherent in converting to a double presicion
% floating point number.

echo off
diary off
