This page is currently under development
In the time being if you have sage installed you can upload this worksheet file to see some examples. Click here to download the worksheet.
We will start with a simple equation
Now to find the derivative in Sage you can use the diff or derivative function (both functions do the same thing, but have different names).
Here is an example of finding the derivative of our equation:
#Remember we must explicitly declare our symbolic variables var('x') eq = 5*x^2 + 6*x + 100 diff(eq) #output: 10x+6 #alternatively since Python is an object oriented language we can use the diff #method associated with the SymbolicArthimetic Class eq.diff( eq ) #output: 10x+6
Example: Using the Chain Rule
f(x) = sin(x) g(x) = cos(x) show( derivative(f(g(x))) ) #Output: -sin(x)cos(cos(x))
Let's continue with the example equation above:
Now to find the 2nd derivative or 3rd,etc the syntax is just like with the first derivative except that you add an additional parameter specifying which derivative you want.
Here is an example:
#Remember we must explicitly declare our symbolic variables var('x') eq = 5*x^2 + 6*x + 100 #Find the second derivative diff( eq, 2 ) #output: 10 #object oriented method eq.diff(2) #Output: 10
If we wanted to find the 3rd or 4th derivative we would just replace the 2 in eq.diff(2) with a 3 or 4.
You can use the derivative method with other functions like solve to accomplish a variety of tasks.
Example: Finding where the derivative equals 0
var('x') eq = 5*x^2 + 6*x + 100 solve( [ eq.diff() == 0 ], x ) #output: x = -3/5
Finding the Equation of the Tangent Line
Sage does not have a built-in function for calculating the tangent line of a function, but writing one is fairly trivial.
Tangent Line Function:
def tangent_line(f,x,a): slope = limit( (f - f(a) ) / (x-a), x=a) eq = slope * (x - a) + f(a) return eq
The function tangent_line takes a function f, a variable x, and a point a. First the function finds the slope by taking
then it creates the equation of the line .
expand( tangent_line( x^2, x, 1 ) ) #output: 2x - 1
Graphing the Tangent Line
The tangent_line function above can also be used to graph a function and it's tangent line at some point x.
Example: Graph and it's tangent line at
Using the function : we can integrate it using the integrate or integral functions.
var('x') eq = 5*x^2 + 6*x + 100 eq.integrate()
Integrating from finite start and end points
Lets say we want to perform this integration:
All we need to is add parameters for the variable we are integrating for and our two endpoints.
Here is the Sage Code:
var('x') eq = 5*x^2 + 6*x + 100 eq.integrate(x,0,100)
Let's say we want perform this integration
It actually works just like with finite start and end points
var('x') integrate( eq2, x, 1, infinity)
However this doesn't work with all functions. For example consider:
var('x') integrate( x^2, x, 1, infinity)
Output: ValueError: Integral is divergent.
Often when talking about indefinite integrals we think of them in terms of
We can write our code in Sage to explicitly express this idea.
limit( integrate( 1/x^2, x, 1, t), t=infinity)
Example of Implicit Differentiation by Dr. Krug:
y = function("y",x) F = x^2 + y^2 - 4*x - 1 show(F.diff())
show( solve(F.diff(x) == 0,diff(y(x),x,1)) )
We can plot the function in Dr. Krug's example using Sage's implicit_plot function.
var('a b') implicit_plot(a^2 + b^2 - 4*a - 1, (-10,10), (-10, 10), plot_points=100)