ARITHMETIC OPERATORS
11 11 |
14 14 |
False False |
True True |
True True |
True True |
NUMERICAL TYPES
INTEGERS AND RATIONAL NUMBERS
10 <type 'sage.rings.integer.Integer'> 10/3 <type 'sage.rings.rational.Rational'> sqrt(10) <type 'sage.symbolic.expression.Expression'> 10 <type 'sage.rings.integer.Integer'> 10/3 <type 'sage.rings.rational.Rational'> sqrt(10) <type 'sage.symbolic.expression.Expression'> |
REAL NUMBERS
10.0000000000000 <type 'sage.rings.real_mpfr.RealLiteral'> 3.33333333333333 <type 'sage.rings.real_mpfr.RealNumber'> 3.16227766016838 <type 'sage.rings.real_mpfr.RealNumber'> 10.0000000000000 <type 'sage.rings.real_mpfr.RealLiteral'> 3.33333333333333 <type 'sage.rings.real_mpfr.RealNumber'> 3.16227766016838 <type 'sage.rings.real_mpfr.RealNumber'> |
COMPLEX NUMBERS
1.00000000000000*I <type 'sage.rings.complex_number.ComplexNumber'> I <type 'sage.symbolic.expression.Expression'> 1.00000000000000 + 1.41421356237310*I <type 'sage.symbolic.expression.Expression'> 1.00000000000000*I <type 'sage.rings.complex_number.ComplexNumber'> I <type 'sage.symbolic.expression.Expression'> 1.00000000000000 + 1.41421356237310*I <type 'sage.symbolic.expression.Expression'> |
I I |
I I |
|
|
1.00000000000000 + 1.41421356237310*I 1.00000000000000 + 1.41421356237310*I |
SYMBOLIC EXPRESSIONS
x <type 'sage.symbolic.expression.Expression'> x + y x <type 'sage.symbolic.expression.Expression'> x + y |
<type 'sage.rings.rational.Rational'> <type 'sage.rings.rational.Rational'> |
<type 'sage.rings.real_mpfr.RealNumber'> <type 'sage.rings.real_mpfr.RealNumber'> |
<type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
<type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
<type 'sage.rings.complex_number.ComplexNumber'> <type 'sage.rings.complex_number.ComplexNumber'> |
<type 'sage.rings.complex_number.ComplexNumber'> <type 'sage.rings.complex_number.ComplexNumber'> |
STRINGS
Single quoted string Sometimes it's good to use double quotes This string contains single quotes ' and double quotes " and spans multiple lines The value is 1.61623300000000 Single quoted string Sometimes it's good to use double quotes This string contains single quotes ' and double quotes " and spans multiple lines The value is 1.61623300000000 |
DEFINITIONS OF THE FUNCTIONS
(Sage assumes that x is symbolic by default.)
x x |
Traceback (click to the left of this block for traceback) ... NameError: name 'y' is not defined Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_8.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpQsdeC9/___code___.py", line 2, in <module>
exec compile(u'y
File "", line 1, in <module>
NameError: name 'y' is not defined
|
<type 'sage.symbolic.expression.Expression'> x |--> a*x^3 <type 'sage.symbolic.expression.Expression'> x |--> a*x^3 |
DERIVATIVE
(derivative is a Sage function for computing symbolic derivatives)
|
36 36 |
12*a 12*a |
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).
x |--> a*x^3 x |--> a*x^3 |
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ a x^{3}
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ a x^{3}
|
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
\newcommand{\Bold}[1]{\mathbf{#1}}\sin\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\sin\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\cos\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\cos\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\tan\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\tan\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\arcsin\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\arcsin\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\arccos\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\arccos\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\arctan\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\arctan\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{x}
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{x}
|
\newcommand{\Bold}[1]{\mathbf{#1}}e^{x}
\newcommand{\Bold}[1]{\mathbf{#1}}e^{x}
|
\newcommand{\Bold}[1]{\mathbf{#1}}\log\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\log\left(x\right)
|
\newcommand{\Bold}[1]{\mathbf{#1}}{\left| x \right|}
\newcommand{\Bold}[1]{\mathbf{#1}}{\left| x \right|}
|
\newcommand{\Bold}[1]{\mathbf{#1}}\overline{x}
\newcommand{\Bold}[1]{\mathbf{#1}}\overline{x}
|
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.
e + 5*I e + 5*I |
55 55 |
e + 5*I e + 5*I |
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)!!!
Voltage at t=1.000s is 36.79V Voltage at t=1.000s is 36.79V |
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.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
Voltage at t=1.000s is 36.79V Voltage at t=1.000s is 36.79V |
\newcommand{\Bold}[1]{\mathbf{#1}}3.29683147847236 \times 10^{-434293}
\newcommand{\Bold}[1]{\mathbf{#1}}3.29683147847236 \times 10^{-434293}
|
|
|