Skip to content

Sage interact: area optimization

March 15, 2010

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.

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), 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 \frac{1}{2}(-2x+3)(\frac{-3}{x}+2) which occurs at x=\frac{-3}{2}.

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


From → computers, math, sage

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: