Sage Notebook "plotting trigonometric functions"

lecture Theoretical Mechanics IPSP

Universität Leipzig, winter term 2020

Author: Jürgen Vollmer (2020)

lizence: Creative Commons Attribution-ShareAlike 4.0 International CC BY-SA 4.0

Sage is an OpenSource Project that implements a broach range of computer-based mathematics and computer algebra in a Jupyter notebook.

Documentation and information on the installation of Sage can be found at https://sagemath.org

A very nice introduction to working with Sage is given in the book Paul Zimmermann, u.a.: "Computational Mathematics with SageMath"

In [1]:
# first: all variable must be declared that will be used later on
t=var("t")
In [2]:
## the command  "plot"  provides the graph of a function
#  -----------------------------------------------------
#  it is stored here in the variable "plt"
#  the plot ranges are prescribed by the the parameters  "xmin, xmax, ymin, ymax"

plt = plot( sin(t), xmin=-2*pi, xmax=4*pi, ymin=-1.5, ymax=1.5 )

# the graph of the function is shown with the command "show()"
show( plt )

# the graph of the function is written to a file with the command "save_image()"
plt.save_image('p01_sine_plot.png')
In [3]:
## the plot ranges are determined by the program if you do not provide them
#  ------------------------------------------------------------------------
#  the consequences are demonstrated in the following two plots

plt2a = plot( (tan(t))^2 )
plt2b = plot( (tan(t))^2, xmin=-6, xmax=8, ymin=-2, ymax=10 )

show( plt2a )
show( plt2b )
In [4]:
## axes labels are specified by the parameter "axes_labels=[]"
#  -----------------------------------------------------------

plt3 = plot( tan(t),  axes_labels=["t","tan(t)"])
show( plt3 )
In [5]:
## axes labels are specified by the parameter "axes_labels=[]"
#  -----------------------------------------------------------
#  ... and for more complicated expressions one may use LaTeX syntax
#      by preceding the strings with 'r' and providing LaTeX expressions in $...$

plt4 = plot( cos(t)+3, 
            xmin=-5, xmax=10, ymin=0, ymax=6,
            axes_labels=[r"$t$", r"$\cos(t)+3$"])
show( plt4 )
In [6]:
## more parameters that control the layout of the plot are described on the help page
#  ----------------------------------------------------------------------------------

?plot