All published worksheets from http://sagenb.org
Image: ubuntu2004
Calculus in Sage
William Stein
2009-05-16 at Sage Days 16
|
Creating Symbolic Expressions
Use the var command to define some symbolic variables. You can separate the variables by commas or spaces in the var command.
Tip: Press shift-enter to evaluate an input cell (instead of clicking "evaluate").
Examples: Create the following expressions: .
Note: that you must put in an asterisk (*) for multiplication.
Most standard functions are defined in Sage. They are named lowercase, much like in Maple. E.g.,
sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth, log, exp, etc.
Example: Construct the symbolic expresion .
Making substitutions
Use the subs method to replace any variables by other variables.
Example: Replace by in the expression .
Expanding Expressions
To expand a symbolic expression with exponents, use the expand method.
Example: Expand the expression .
Creating Symbolic Functions
To create a symbolic function, use the notation f(x,y) = x^3 + y. A symbolic function is just like a symbolic expression, except you can call it without having to explicitly use subs or name variables and be sure that the order is what you want.
Problem: Create the functions .
2D Plotting
Use the plot command to plot a function of 1 variable. TIP: Type plot(<tab key> to find out much more about the plot command.
Here's a the same plot, but you can adjust many of the parameters to the plot command interactively.
Example: I made the following using the above interactive plotter with .
You can plot many other things, including polygons, parametric plots, polar plots, implicit plots, etc.:
line, polygon, circle, text, polar_plot, parametric_plot, circle, implicit_plot
You superimpose plots using +.
Example: Draw 3 concentric circles that are red, green and blue. [Hints: Use rgbcolor, and give the aspect_ratio=1 option to the show command, as above.]
3D Plotting
You can also plot functions of two variables using the plot3d command. Also, there are line3d, sphere, text3d, cube, parametric_plot3d, etc. commands. Bill Cauchois will demo 3d plotting much more in the next talk.
Example: Draw a 3d plot of the function .
Computing Integrals and Derivatives
You can symbolically integrate or differentiate functions, compute limits, Taylor polynomials, etc.