Overview of Key Python Commands in MATH 152

(Alphabetical with newest commands on top)

 

Command

Summary

Online Documentation

 

 

 

abs()

Absolute value

https://docs.sympy.org/latest/modules/functions/elementary.html#abs

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

collect()

Collect terms by like powers of the specified variable

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

cumsum()

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

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

exp()

Exponential function (can also use E**...)

https://docs.sympy.org/latest/modules/functions/elementary.html#exp

expand()

Expand a symbolic expression.

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

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

lambda

defines an anonymous function

https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions
(See also examples in mpmath.nsum() )

nsolve()

Numerically approximate a solution to an equation

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.)

nsum()

Sums an infinite series (in MPMATH.  NOTE this command requires “inf” instead of oo for infinity)

https://docs.sympy.org/0.7.6/modules/mpmath/calculus/sums_limits.html

plot()

Plot a function

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

plot

Numerical plotting function (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()

Simplify an algebraic expression.

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

simps

Approximate integrals using Simpson’s Rule (in SCIPY.INTEGRATE)

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html

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 (in NUMPY)

https://numpy.org/doc/stable/reference/generated/numpy.sum.html

symbols()

Define a variable to be symbolic (NOTE: Can also include options like real=True or positive=True)

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

trapz

Approximate integrals using the Trapezoid Rule. (in SCIPY.INTEGRATE)

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapz.html