Created
November 27, 2012 23:37
-
-
Save lidavidm/4157972 to your computer and use it in GitHub Desktop.
Calculus, Chapter 16.4 problem 16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 "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 "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