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')
t     = symbols('t')

Example

Evaluate the line integral along the parabola from to .

x = t
y = 2*sqrt(t)

f = y  

s = sqrt( diff(x,t)**2 + diff(y,t)**2 )

# integration
integrate(f*s,[t,3,24])

Example

Find the work done by the vector field in moving a particle along the helix from the point to .

Note:

x = cos(t)
y = sin(t)
z = t

F = [x**2 + y**2 + z**2  , 0   , 0]

integrate(
          F[0]*diff(x,t) + F[1]*diff(y,t) + F[2]*diff(z,t),
          [t,0,4*pi]
         )


Example

Evaluate along the arc of the circle in the first quadrant from to .

x = cos(t)
y = sin(t)

F = [2*x*y, x**2 - y**2]

integrate(
          F[0]*diff(x,t) + F[1]*diff(y,t),
          [t,0,pi/2]
         )

Example

Prove that is a conservative force field. Hence find the work done in moving an object in this field from point to .

Note:

If a vector field is conservative then

# reset variables from previous examples
x,y,z = symbols('x y z') 

def curl(F):
    c1 = diff(F[2],y) - diff(F[1],z)
    c2 = diff(F[0],z) - diff(F[2],x)
    c3 = diff(F[1],x) - diff(F[0],y)
    return [c1,c2,c3]
F = [(y**2 *cos(x) + z**3), 2*y* sin(x) - 4. , 3*x*z**2 + z ]
curl(F)

Zero curl implies conservative vector field.


Example

Evaluate over the triangle with vertices , , and .

pp1

x,y = symbols('x y')

integrate( 
    integrate(x**2 + y**2, [x,y,2-y]),
    [y,0,1])


Example

Evaluate

over the region and .

pp2

x,y = symbols('x y')


# does not work in one shot
integrate((x + 2*y)**(-Rational(1,2)), [x, y**2+1, 1+2*y])

#manually simlipy one radical

integrate(2*sqrt(4*y + 1) - 2*(y+1),[y,0,2])