All published worksheets from http://sagenb.org
Image: ubuntu2004
1. INTRODUCTION
ARITHMETIC OPERATORS
NUMERICAL TYPES
INTEGERS AND RATIONAL NUMBERS
REAL NUMBERS
COMPLEX NUMBERS
SYMBOLIC EXPRESSIONS
STRINGS
DEFINITIONS OF THE FUNCTIONS
(Sage assumes that x is symbolic by default.)
DERIVATIVE
(derivative is a Sage function for computing symbolic derivatives)
TYPESET - NOT CHECKED AND CHECKED - Near the top of every worksheet is a check box with the label Typeset.
(has no effect on the print or show functions).
PLOT FUNCTION
CUSTOMIZATION OF PLOT FUNCTION
a function is called using the syntax:
result = function_name(argument_1, argument_2, … , argument_n, keyword=value)
POSITIONAL ARGUMENTS
Positional arguments are required, and they must occur in the correct order.
first argument: symmbolic expresion
second argument: A TUPLE - contains the independent variable, the minimum value and the maximum value of the plotting domain.
KEYWORD ARGUMENTS
A keyword argument is optional and it must come after all the positional arguments.
BUILT-IN FUNCTIONS
THE RESTORE AND RESET FUNCTIONS
Restore function can be used to restore predefined global variables (such as i and e) to their default values. If we call restore without any arguments, it will restore all the predefined variables to their default values.
Reset deletes all the variables we have defined, restores all global variables to their default values, and resets the interfaces to other computer algebra systems.
HOW TO DEFINE MY OWN FUNCTION?
def function_name(argument_1, argument_2, … , argument_n):
"""
Documentation string here
"""
statement one
statement two
...
return some_value
Make sure that you consistently indent each line inside the function (indentation is used to delimit blocks of code)!!!
Our function even has documentation like a built-in function!
File: /tmp/tmp2WYzMF/___code___.py
Type: <type 'function'>
Definition: RC_voltage(v0, R, C, t)
Docstring:
Calculate the voltage at time t for an R-C circuit with initial voltage v0.
FUNCTIONS WITH KEYWORDS ARGUMENTS
If there are keyword arguments, they must be defined after the positional arguments.
def function_name(argument_1, argument_2, … , argument_n, keyword_arg_1=default_value ,… , keyword_arg_n=default_value ):
"""
Documentation string here
"""
statement one
statement two
...
return some_value