# Sage interact: area optimization

Sage notebook code which produces an interactive area optimization problem typical of a first semester calculus course. The main feature is the slider which controls the slope of the hypotenuse.

@interact def _(s=slider(-10,-0.1,0.1,default=-2,label='slope')): print "Try to minimize the area of the triangle whose hypotenuse\npasses through (2,3):" G=line([(0,-2*s+3), (-3/s+2,0)]) #s*(x-2)+3,(x,-1,6)) G += polygon( [ (0,0), (0,-2*s+3), (-3/s+2,0) ], rgbcolor=hue(0.75)) G += point([(0,-2*s+3),(-3/s+2,0),(2,3),(0,0)],rgbcolor=hue(0.95),pointsize=25) G.show(ymin=-1, ymax=10, xmin=-1, xmax=6, figsize=3) print "Area = %f" % (1/2*(-2*s+3)*(-3/s+2))

Here is a screenshot (since I couldn’t yet figure out how to get the example published and working on the public Sage server).

The (calculus) solution is to find the minimum (positive) value of the function which occurs at .

There are lots of great examples of the interact module on the Sage wiki: Examples.

Advertisements

Leave a Comment