% 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)) Warning: Explicit integral could not be found. > In /usr/local/matlab5/toolbox/symbolic/@sym/int.m at line 58 In /www/users/rll/courses/math246.f98/psa/probA11.m at line 17 ans = 3.9775 % 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) ans = 1/3*2^(1/2)+(-2/3*2^(1/2)+4/3)*EllipticF(1/2*2^(1/4)*(2+2^(1/2))/(2*2^(1/2)+2)^(1/2),2*2^(3/4)/(2+2^(1/2))) % 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) ans = 1.0894 % 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)) ans = 1.7725 % Now let's compare to the square root of pi, using vpa to evaluate % this number more accurately than double. vpa('sqrt(pi)') - ans ans = -.766658649982580e-16 % 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