MATH 152 Python Commands


Command

Summary

Online Documentation

Rational()

Define a rational expression you wish to keep rather than actually dividing.

https://docs.sympy.org/latest/tutorial/gotchas.html#two-final-notes-and

sum() or Sum()

Sum a list of numbers. NOTE for infinite series, the Sum command with .doit may work better.

https://docs.sympy.org/latest/modules/concrete.html#concrete-class-reference

summation()

Computes a summation with other variables in it (i.e., a power series!)

https://docs.sympy.org/latest/modules/concrete.html#sympy.concrete.summations.summation
(NOTE that range in this command is INCLUSIVE on both endpoints!)




apart()

The partial fraction decomposition of an expression

https://docs.sympy.org/latest/tutorial/simplification.html#apart

arange()

Generates an equally-spaced array for numeric computation/plotting (in NUMPY)

https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html

cumsum()

Generates the cumulative sum of the elements of a list. (i.e., the partial sums!)

https://docs.scipy.org/doc/numpy/reference/generated/numpy.cumsum.html

.evalf()

Evaluate to floating point

https://docs.sympy.org/latest/tutorial/basic_operations.html#evalf

factor()

Factor a symbolic expression

https://docs.sympy.org/latest/tutorial/simplification.html#factor

integrate()

Integrate a function

https://docs.sympy.org/latest/tutorial/calculus.html#integrals

nsolve()

Numerically solve an equation given an initial guess

https://docs.sympy.org/latest/modules/solvers/solvers.html
(NOTE: Use Ctrl-F to find the nsolve syntax and examples as they are far down the page.)

plot() 

Plot a function

https://docs.sympy.org/latest/modules/plotting.html#plotting-function-reference

plot()

Numeric plotting tool; good for plotting points (sequences). In MATPLOTLIB.PYPLOT

https://matplotlib.org/tutorials/introductory/pyplot.html

(NOTE the import command-this is required before running the command to distinguish this command from the sympy.plot command! The “as plt” is used to simplify future typing of the command.)

print()

Display variable values and text output

https://docs.python.org/3/library/functions.html#print

range(a,b)

creates a list of integers from a to b-1 (NOTE!)

https://docs.sympy.org/latest/modules/sets.html#range
(can be done in lowercase)

.simplify() or simplify()

Simplify a symbolic expression

https://docs.sympy.org/latest/tutorial/simplification.html#simplify

solve()

Symbolically solve an equation

https://docs.sympy.org/latest/modules/solvers/solvers.html

.subs()

Substitute value(s) into an expression

https://docs.sympy.org/latest/tutorial/basic_operations.html#substitution

sum()

Sum a list of numbers.

https://docs.sympy.org/latest/modules/concrete.html#concrete-class-reference

symbols()

Define a symbolic variable (with optional properties, such as real=true or positive=true)

https://docs.sympy.org/latest/tutorial/intro.html#a-more-interesting-example

ylim

Sets the ymin and ymax of a symbolic plot (within the plot command)

https://docs.sympy.org/0.7.5/modules/mpmath/plotting.html