Basic Sage Facts 1. Introduction Sage on open-source alternative to commercial computer algebra systems (CAS) such as Maple, Mathematica, and Matlab. Sage has many capabilities similar to the commercial versions. They include graphing, solving equations analytically or numerically, and symbolic manipulations such as differentiation and antidifferentiation of functions. The purpose of this handout is to (re)introduce you to Sage and some of its general features. 2. Workbooks, Folders, & Worksheets A Sage session begins by using a web browser, such as Firefox or Google, to open the Sage login page with url sage.luther.edu Once logged in, your Sage “workbook” will open. The Sage workbook and has three folders, Active, Archived, and Trash. A worksheet is made up of a collection of cells. The Active folder’s listing of worksheets is what you will see upon opening the workbook. If you want to work between multiple worksheets, you need to open multiple Sage workbooks. 3. Cell Manipulations A cell within a Sage worksheet is where a command, or sequence of commands, may be carried out. A cell is represented as a rectangular region in the worksheet, outlined by a thin blue boundary. Activating the cell plot(x∧2-2*x-3,(x,-1,3)) generates a plot of the function y = x2 + 1 on the x-interval [−1, 3]. A cell can be added between existed cells by clicking the blue line when it appears as the pointer is dragged vertically between cells. A new cell may be designated a text/HTML cell by “shift-clicking” the blue line between cells. A cell is split using “control-;”. Two adjacent cells are joined by “control-backspace” in the second cell of the sequence. A cell is deleted by deleting all of the cell’s content and then hitting “backspace.” 4. On-Line Help Sage has an on-line help system that is invoked by typing the command name followed by a question mark in a cell. For example plot? 5. Symbols and Conventions The following table summarizes some basic Sage symbols and conventions. Symbol { } [ ] ’ ’ f(x) Description set delimiter (an unordered list) list delimiter (lists are ordered) string delimiter function definition Example {a, b, c } [ a, b, c ] text(’txt’,(x,y)) f(x)=x^2 + 2*x +1 Table 1: Basic Symbols and Operations 6. Operations, Functions, and Constants The table below provides information on basic mathematical operations, functions, and constants. Symbol +, -, *, /, ∧ sin, cos, tan, cot, sec, csc arcsin, arctan, ... sinh, tanh, ... exp ln log base b abs sqrt factorial =, <>, <=, <, >, >= pi,i,e oo Description add, subtract, multiply, divide, power trigonometric functions Example 3*x∧(-4) + x/7 sin(x)*cos(x+1) inverse trigonometric functions hyperbolic functions natural exponential function natural logarithm logarithm base b absolute value square root factorial equal, not equal, less than or equal, less than, √ greater than, greater than or equal π, i = −1, e ∞ tanh(sin(1)) tanh(sin(1)) exp(1/x) ln(x + 1) log(5,b) abs(x+2) sqrt(1-x) factorial(6) x <>7 x >= 9 exp(Pi*I) limit(f(x), x=oo) Table 2: Basic Operations, Functions, and Constants 7. Frequently Used Commands Command var plot parametric plot Description define a Sage variable draw a 2-dimensional plot 2-dimensional parametric plot implicit plot find root limit diff draw a 2-dimensional plot of an implicitly defined curve draw a 3-dimensional plot draw a 3-dimensional plot of an implicitly defined surface solve a single equation solve a system of equations find the root numerically calculate a limit find the derivative integral integral find the indefinite integral find the definite integral numerical integral desolve numerical approximation analytic solution to an ODE general solution particular solution plot3d implicit plot3d solve Example x=var(’x’) plot(sin(x),(x,0,pi) parametric_plot((cos(t),sin(t)), (t,0,2*pi)) implicit_plot(x∧2+y∧2==4,(x,-3,3), (y,-3,3)) plot3d(x*cos(y),(x,0,2),(y,-pi,pi)) implicit_plot3d(x∧2+y∧2+z∧2==8, (x,-3,3),(y,-3,3),(z,-3,3)) solve(x + 2 == 5, x) solve([2*x + 3*y == 1,x - 4*y == 2],x,y) find_root(x + 2 - 5,0,5) limit(sin(1/x),x=oo) diff(x*sin(y),x) NOTE: diff=differentiate=derivative integral(x*sin(x),x) integral(x + 1,(x,0,1)) NOTE: integral=integrate numerical_integral(exp(x^2),0,1) y=function(’y’,t) desolve(diff(y,t)==y, y) desolve(diff(y,t)==y, y, ics=[0,2]) Table 3: Frequently Used Commands