5.6 Substitution and Area Between Curves

This page offers a solution using Octave to Exercise 5.6 #94. This solution could be used verbatim in MATLAB.

Octave / MATLAB


Octave / MATLAB

Exercise 5.6 #94

$f(x)=x^2\cos{x}$, $\,\,\,g(x)=x^3-x$

(a) Plot the curves together to see what they look like and how many points of intersection they have.

First note that $f(0)=g(0)$ by inspection. For $x\neq 0$, $f(x)=g(x)$ is equivalent to $x\cos{x}+1=x^2$. For $x>2$, we have $x\cos{x}+1 < x\cos{x}+x=(\cos{x}+1)x\leq 2x < x^2$ and so the equation does not have any solutions with $x>2$. Similarly, for $x<-2$, we have $x\cos{x}+1 < x\cos{x}-x=(\cos{x}-1)x\leq -2x < x^2$ and thus the equation does not have any solution with $x<-2$. So if we plot over the interval $[-2,2]$ we will not miss any intersections.

octave:1> ezplot('x^2*cos(x)', [-2 2]) octave:2> hold on octave:3> ezplot('x^3-x', [-2 2])

This step is not strictly necessary, but from this first plot we see that we could "zoom in" a bit without losing any of the points of intersection.

octave:4> xlim([-1 1.5]) octave:5> ylim([-1 1])

(b) Use the numerical equation solver in your CAS to find all the points of intersection.

The plot enables us to pass reasonable starting values to fzero() to find (approximations to) all three solutions of $f(x)-g(x)=0$, i.e. the solutions to $f(x)=g(x)$.

octave:6> a = fzero( @(x) x.^2*cos(x)-(x.^3-x), -0.7 ) a = -0.68517 octave:7> b = fzero( @(x) x.^2*cos(x)-(x.^3-x), 0 ) b = 0 octave:8> c = fzero( @(x) x.^2*cos(x)-(x.^3-x), 1.2 ) c = 1.1984

(c) Integrate $|f(x)-g(x)|$ over consecutive pairs of intersection values.

We'll use the numerical integrator quadgk(), but other choices would yield comparable accuracy.

octave:9> area1 = quadgk( @(x) abs( x.^2.*cos(x)-(x.^3-x) ), a, b ) area1 = 0.087095 octave:10> area2 = quadgk( @(x) abs( x.^2.*cos(x)-(x.^3-x) ), b, c ) area2 = 0.54932

(d) Sum together the integrals found in part (c).

octave:11> area1 + area2 ans = 0.63642

Thanks to the use of abs() we didn't need to worry about the order of subtraction in our integrands, and we don't really even need to compute two separate integrals to find the total area between the two curves.

octave:12> quadgk( @(x) abs( x.^2.*cos(x)-(x.^3-x) ), a, c ) ans = 0.63643