Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – calculating limits


The concept of the limit is often used to define the integral and the derivative. Run the following code to see how to compute limits with Sage:

var('x')

# Something easy
f(x) = 1 / x
print("Limit of 1/x as x->0+: {0}".format(limit(f, x=0, 
    dir='plus')))
print("Limit of 1/x as x->0-: {0}".format(limit(f, x=0
    dir='minus')))
p1 = plot(f, (x, -1, 1), detect_poles='show')
p1.axes_range(-1, 1, -10, 10)
p1.show()

# Something more complex
g(x)=(2 * x + 8) / (x^2 + x - 12)
g.show()
print("Limit of g(x) as x->-4: {0}".format(limit(g, x=-4)))

h(x) = (x^2 - 4) / (x - 2)
h.show()
print("Limit of h(x) ax x->2: {0}".format(lim(h, x=2)))

The results are shown in the following screenshot:

What just happened?

We started out by defining a simple function with a discontinuity at zero. We used the function limit (or lim) to compute the limit as x approaches zero. The first argument to limit is a function, and the second argument is the value at which...