Areas Between Curves
In this example, we demonstrate how to find areas between curves. Suppose we have the upper half of an ellipse whose equation is y=4/3*sqrt(9-x^2) and a line y=2x. We wish to find the area under the ellipse, above the x-axis, and to the left of the line. The steps to solve this problems are:
1) Graph the curves to identify the region (plot)
2) Find the point(s) of intersection (solve)
3) Compute an appropriate integral to find the area in question. (integrate)
As always, we first import commands from the sympy package, define our symbolic variable x, and create expressions f and g for the ellipse and line respectively. Step 1, we use the plot command to visualize the region after running our command matplotlib notebook Note that we are plotting both graphs on the same axis, so we use tuples around each plot. Step 2, we find the intersection using the solve command. Note that we print the result in case there are several solutions to identify which one is appropriate. In this case, we obtain only one solution, so we specify it using the [0] index (remember Python starts counting with the 0th element!). Looking at the graph, we see the desired area is found by integrating f from -3 to 0, then integrating f-g from 0 to our solution above (NOTE that integrating right minus left with respect to y is not any easier). We print both answers to help with debugging if necessary, then our final answer.