area between curves

2491 days ago by chrisphan

baseframe = plot(4 - x^2/4, x, 0, 3.5, rgbcolor=(0.7, 0, 0)) + plot(cos(3*x), x, 0, 3.5, rgbcolor=(0, 0, 0.7)) firstframe = baseframe + text("$y = 4 - x^2/4$", (1, 4.1), rgbcolor=(0.7, 0,0)) + text("$y = \cos(3x)$", (1, -1.25), rgbcolor=(0, 0, 0.7)) def boxes(offset): retframe = text("", (0,0)) deltax = 0.1 for i in range(0, 35): leftend = i*deltax rightend = (i+1)*deltax upper = 4 - leftend^2/4 lower = cos(3*leftend) movement = (-1)*offset * lower upper = upper + movement lower = lower + movement retframe = retframe + polygon([(leftend, lower), (leftend, upper), (rightend, upper), (rightend, lower)], alpha=0.5, rgbcolor=(1, 1, 0)) retframe = retframe + line([(leftend, lower), (leftend, upper), (rightend, upper), (rightend, lower), (leftend, lower)], rgbcolor=(0, 1, 0)) return retframe lastframe = boxes(1) + plot(4 - x^2/4 - cos(3*x), x, 0, 3.5, rgbcolor=(0, 0.5, 0)) + text("$y = 4 - x^2/4 - \cos(3x)$", (2, 4.7), rgbcolor=(0, 0.5, 0)) framelist = [firstframe]*7 framelist = framelist + [boxes(j/25) + baseframe for j in range(0, 26)] framelist = framelist + [lastframe] * 10 show(animate(framelist, xmin = 0, xmax = 3.5, ymin = -1.5, ymax = 5, figsize=[10, 7])) 
       
plot([x^2 - 4, 2 - x^2], x, -2, 2) 
       

                                
                            

                                
plot([sqrt(x)+1, x, 2*x], x, 0, 3, ymax = 3)