Movatterモバイル変換


[0]ホーム

URL:


SageMath Logo
GitHub·Wiki·Questions?· Sponsor·Donate
Online:CoCalc·SageCellorInstall,Clone
FT

Quickstart

This is a short introduction in how to interact with SageMath. Make sure you have installed it according to theinstallation guide. There are also niceScreencasts for introduction available. Make sure to read more about SageMath in theSageMath Tutorial!

Basics

sage:1+12sage:V = QQ^3sage:V.[tab key]...V.base_ringV.basisV.coordinates...
SageMath uses the basic user-interface principle of "question and answer" found in many other software systems. You enter an expression and after pressing theReturn key in the command line interface or hittingShift+Return in the notebook interface, SageMath evaluates your expression and returns the answer. –read more
Tab-completion helps you enter commands. On the command-line, it also provides history and reverse lookup search. –read more

Classes of Objects

sage:R = RealIntervalField(100)sage:RReal Interval Field with 100 bits of precisionsage:a = R((-1,0)); a-1.?sage:b = sin(a); b-1.?sage:c = a*b; c.diameter()0.84147098480789650665250232163
As you can see in the previous example, SageMath knows about mathematical objects embedded into the Python language. Every quantity - a real number, a polynomial, a matrix, and so on - belongs to aparent, and this tells SageMath how to perform operations on the quantity.
In the example on the left, R is defined as the class of all intervals of real values with 100 bits of precision. Then an interval is created and stored ina, the functionsin is applied and stored inb. In the end they are multiplied and the diameter is calculated.sin is a function that "knows" about intervals, as well as the multiplication does, anddiameter() is a method of an interval instance object.

Interactive Help

sage:c.diameter?Docstring:   If 0 is in "self", then return "absolute_diameter()", otherwise   return "relative_diameter()".   EXAMPLES:      sage: RIF(1, 2).diameter()      0.666666666666667      ...
The example above shows that there are thousands of functions and methods. SageMath comes witha built-in help system and you do not have to memorize them all. Entering a question mark after a method shows the description and additional information about that method. The example on the left shows the documentation for thediameter method from the previous example.

Symbolic Maths

sage:f = 1 - sin(x)^2sage:f-sin(x)^2 + 1sage:unicode_art(f)  # pretty printing       21 - sin (x)sage:f.simplify_trig()cos(x)^2sage:f(x=pi/2)0sage:f(x=pi/3)1/4sage:integrate(f, x).simplify_trig()1/2*sin(x)*cos(x) + 1/2*xsage:unicode_art(integrate(f, x).simplify_trig())x   sin(x)⋅cos(x)─ + ─────────────2         2sage:f.differentiate(2).substitute({x: 3/pi})2*sin(3/pi)^2 - 2*cos(3/pi)^2sage:unicode_art(f.differentiate(2).substitute({x: 3/pi}))       2⎛3⎞        2⎛3⎞- 2⋅cos ⎜─⎟ + 2⋅sin ⎜─⎟        ⎝π⎠         ⎝π⎠
Here we define a function $$f$$, simplify it, evaluate it at $$\pi/2$$ and $$\pi/3$$ and integrate it with simplification. After that, $$f$$ is differentiated two times and $$x$$ is substituted by $$3/\pi$$.

Numerical Maths

sage:g = sin(x) + (1- x^2)sage:find_root(g, 0, 2)1.4096240040025754sage:var('x y z')(x, y, z)sage:f = (1 + (y+x^2)^2 + (1+z+y^2)^2)^2sage:f            2     2         2 2     2     ((z + y  + 1)  + (y + x )  + 1)sage:minimize(f,[1,2,3],algorithm='powell',verbose=1)Optimization terminated successfully.     Current function value: 1.000059     Iterations: 2     Function evaluations: 84(-0.000607497243458, 0.00486816565959, -1.00243223164)
On the left side, a root of the function
$$g(x) = sin(x) + (1-x^2)$$
is found numerically.
Below, the function
$$f(x,y,z) = (1 + (y + x^2)^2 + (1+z+y^2)^2)^2$$
is minimized using the "powell" algorithm.
Tour Research ·Tour Graphics
··
Locations of visitors to this page

[8]ページ先頭

©2009-2026 Movatter.jp