Skip to content

Instantly share code, notes, and snippets.

@lidavidm
Created November 27, 2012 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidavidm/4157972 to your computer and use it in GitHub Desktop.
Save lidavidm/4157972 to your computer and use it in GitHub Desktop.
Calculus, Chapter 16.4 problem 16
# -*- coding: utf-8 -*-
# Warning: takes FOREVER to run!
from sympy.core import Symbol, diff, pi, sympify
from sympy.integrals import integrate
from sympy.functions import sin, cos, sqrt
x, y, t = map(Symbol, 'xyt')
P = 2*x - (x**3) * (x**5)
Q = (x**3) * (y ** 8)
# Line integral
r = (cos(t), 2 * sin(t))
integrand = (P.subs({x: r[0], y: r[1]}) * diff(r[0], t) +
Q.subs({x: r[0], y: r[1]}) * diff(r[1], t))
print "LINE INTEGRAL"
print
print "Path:", r
print "Integrand:", integrand
print "Result:", integrate(integrand, (t, 0, 2 * pi))
# Green’s theorem
integrand = diff(Q, x) - diff(P, y)
xlimits = (x, -1, 1)
ylimits = (y, -2 * sqrt(1 - x**2), 2 * sqrt(1 - x**2))
print "GREEN’S THEOREM"
print
print "Integrand:", integrand
print "Limits: x:", xlimits
print " y:", ylimits
print integrate(integrand, ylimits, xlimits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment