Practice Set B: Problems 1-9

 

1.

(a)

[X, Y] = meshgrid(-1:0.1:1, -1:0.1:1); contour(X, Y, 3*Y + Y.^3 - X.^3, 'k')  

 

  

 

[X, Y] = meshgrid(-10:0.1:10, -10:0.1:10); contour(X, Y, 3*Y + Y.^3 - X.^3, 'k')

 

  

 

Here is a plot with more level curves.

 

[X, Y] = meshgrid(-10:0.1:10, -10:0.1:10); contour(X, Y, 3*Y + Y.^3 - X.^3, 30, 'k')  

 

  

 

(b)

Now we plot the level curve through 5.

 

[X, Y] = meshgrid(-5:0.1:5, -5:0.1:5); contour(X, Y, 3.*Y + Y.^3 - X.^3, [5 5], 'k') 

 

  

 

(c)

We note that f(1, 1) = 0, so the appropriate command to plot the level curve of f through the point (1, 1) is

 

[X, Y] = meshgrid(0:0.1:2, 0:0.1:2); contour(X, Y, Y.*log(X) + X.*log(Y), [0 0], 'k')

 

Warning: Log of zero.

Warning: Log of zero.

  

 

2.

We find the derivatives of the given functions: 

 

syms x r  

 

(a)

diff(6*x^3 - 5*x^2 + 2*x - 3, x)  

 

ans =

18*x^2-10*x+2  

 

(b)

diff((2*x - 1)/(x^2 + 1), x)  

 

ans =

2/(x^2+1)-2*(2*x-1)/(x^2+1)^2*x  

 

simplify(ans)  

 

ans =

-2*(x^2-1-x)/(x^2+1)^2  

 

(c)

diff(sin(3*x^2 + 2), x)  

 

ans =

6*cos(3*x^2+2)*x  

 

(d)

diff(asin(2*x + 3), x)  

 

ans =

1/(-2-x^2-3*x)^(1/2)  

 

(e)

diff(sqrt(1 + x^4), x)  

 

ans =

2/(1+x^4)^(1/2)*x^3  

 

(f)

diff(x^r, x)  

 

ans =

x^r*r/x  

 

(g)

diff(atan(x^2 + 1), x)  

 

ans =

2*x/(1+(x^2+1)^2)  

 

3.

We compute the following integrals.

 

(a)

int(cos(x), x, 0, pi/2)  

 

ans =

1  

 

(b)

int(x*sin(x^2), x)  

 

ans =

-1/2*cos(x^2)  

 

To check the indefinite integral, we just differentiate.

 

diff(-cos(x^2)/2, x)  

 

ans =

x*sin(x^2)  

 

(c)

int(sin(3*x)*sqrt(1 - cos(3*x)), x)  

 

ans =

2/9*(1-cos(3*x))^(3/2)  

 

diff(ans, x)  

 

ans =

sin(3*x)*(1-cos(3*x))^(1/2)  

 

(d)

int(x^2*sqrt(x + 4), x)  

 

ans =

2/7*(x+4)^(7/2)-16/5*(x+4)^(5/2)+32/3*(x+4)^(3/2)  

 

diff(ans, x)  

 

ans =

(x+4)^(5/2)-8*(x+4)^(3/2)+16*(x+4)^(1/2)  

 

simplify(ans)  

 

ans =

x^2*(x+4)^(1/2)  

 

(e)

int(exp(-x^2), x, -Inf, Inf)  

 

ans =

pi^(1/2)  

 

4.

(a)

syms x; int(exp(sin(x)), x, 0, pi)  

 

Warning: Explicit integral could not be found.

> In C:\MATLABR12\toolbox\symbolic\@sym\int.m at line 58

ans =

int(exp(sin(x)),x = 0 .. pi)  

 

format long; quadl('exp(sin(x))', 0, pi)  

 

ans =

   6.20875803571375  

 

(b)

quadl('sqrt(x.^3 + 1)', 0, 1)  

 

ans =

   1.11144798484585  

 

(c)

MATLAB integrated this one exactly in 4(e) above; let's integrate it numerically and compare answers.  Unfortunately, the range is infinite, so to use quadl we have to approximate the interval.  Note that

 

exp(-35)  

 

ans =

    6.305116760146989e-016  

 

which is close to the standard floating point accuracy, so:

 

format long; quadl('exp(-x.^2)', -35, 35)  

 

ans =

   1.77245385102263  

 

sqrt(pi)  

 

ans =

   1.77245385090552  

 

The answers agree up to 10 digits.

 

5.

(a)

limit(sin(x)/x, x, 0)  

 

ans =

1  

 

(b)

limit((1 + cos(x))/(x + pi), x, -pi)  

 

ans =

0  

 

(c)

limit(x^2*exp(-x), x, Inf)  

 

ans =

0  

 

(d)

limit(1/(x - 1), x, 1, 'left')  

 

ans =

-inf  

 

(e)

limit(sin(1/x), x, 0, 'right')  

 

ans =

-1 .. 1  

 

This means that every real number in the interval between -1 and +1 is a "limit point" of sin(1/x) as x tends to zero.  You can see why if you plot sin(1/x) on the interval (0, 1].

 

ezplot(sin(1/x), [0 1])  

 

6.

(a)

syms k n r x z  

 

symsum(k^2, k, 0, n)  

 

ans =

1/3*(n+1)^3-1/2*(n+1)^2+1/6*n+1/6  

 

simplify(ans)  

 

ans =

1/3*n^3+1/2*n^2+1/6*n  

 

(b)

symsum(r^k, k, 0, n)  

 

ans =

r^(n+1)/(r-1)-1/(r-1)  

 

pretty(ans)  

 

 

                                (n + 1)

                               r            1

                               -------- - -----

                                r - 1     r - 1  

 

 

(c)

symsum(x^k/factorial(k), k, 0, Inf)  

 

??? Error using ==> fix

Function 'fix' not defined for variables of class 'sym'.

 

Error in ==> C:\MATLABR12\toolbox\matlab\specfun\factorial.m

On line 14  ==> if (length(n)~=1) | (fix(n) ~= n) | (n < 0)  

 

Here are two ways around this difficulty.  The second method will not work with the Student Version.

 

symsum(x^k/gamma(k + 1), k, 0, Inf) 

 

ans =

exp(x)  

 

symsum(x^k/maple('factorial', k), k, 0, Inf)  

 

ans =

exp(x)  

 

(d)

symsum(1/(z - k)^2, k, -Inf, Inf)  

 

ans =

pi^2+pi^2*cot(pi*z)^2  

 

7.

(a)

taylor(exp(x), 7, 0)  

 

ans =

1+x+1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^6  

 

(b)

taylor(sin(x), 5, 0)  

 

ans =

x-1/6*x^3  

 

taylor(sin(x), 6, 0) 

 

ans =

x-1/6*x^3+1/120*x^5  

 

(c)

taylor(sin(x), 6, 2) 

 

ans =

sin(2)+cos(2)*(x-2)-1/2*sin(2)*(x-2)^2-1/6*cos(2)*(x-2)^3+1/24*sin(2)*(x-2)^4+1/120*cos(2)*(x-2)^5  

 

(d)

taylor(tan(x), 7, 0)  

 

ans =

x+1/3*x^3+2/15*x^5  

 

(e)

taylor(log(x), 5, 1)  

 

ans =

x-1-1/2*(x-1)^2+1/3*(x-1)^3-1/4*(x-1)^4  

 

(f)

taylor(erf(x), 9, 0)  

 

ans =

2/pi^(1/2)*x-2/3/pi^(1/2)*x^3+1/5/pi^(1/2)*x^5-1/21/pi^(1/2)*x^7  

 

8.

(a)

syms x y; ezsurf(sin(x)*sin(y), [-3*pi 3*pi –3*pi 3*pi])  

 

 

(b)

syms x y; ezsurf((x^2 + y^2)*cos(x^2 + y^2), [-1 1 -1 1]) 

 

 

9.

You can't do animations in an M-Book.  But from the Command Window, you can type:

 

T = 0:0.01:1; 

for j = 0:16

  fill(4*cos(j*pi/8)+(1/2)*cos(2*pi*T), ...

  4*sin(j*pi/8)+(1/2)*sin(2*pi*T), 'r'); axis equal; axis([-5 5 –5 5]);

  M(j+1) = getframe;

end 

movie(M)