Setting up python environment

# reset all previously defined varibles
%reset -f

# import everything from sympy moduleb 
from sympy import *

# pretty math formatting
init_printing()   # latex

Symbolic variables must be declared

x,y,z = symbols('x y z')

Function definition

## Example 1

f = 2*x**3  # define function
f           # print function

## Example 2

g = x**2 + x*y**2 # define function
g           # print function

Function Evaluation

# f(0)
f.subs(x,0)
# f(1)
f.subs(x,1)
# g(x=2,y=3)
g.subs([(x,2),(y,3)])

Plotting

## Graph of f = x^2

f = x**2

plot(f)

png

<sympy.plotting.plot.Plot at 0x7f5b50e6a410>
## multiple graph in same window

f = x**2
g = x**3

p = plot(f,g, (x, -2, 2),show=False, legend=True  )

p[0].line_color = 'blue'
p[1].line_color = 'green'


p[0].label      = 'f(x)'
p[1].label      = 'g(x)'
p.show()

png

## undocking plots out of browser
%matplotlib qt  

f = x**2
plot(f)

<sympy.plotting.plot.Plot at 0x7f5b173ce850>
## forcing plots inside browser
%matplotlib inline

f = x**2
plot(f)

png

<sympy.plotting.plot.Plot at 0x7f5b2c0869d0>