Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
#######
#
# E-scripts on ipython.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/ipython.e>
#           or at <http://angg.twu.net/e/ipython.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######



# «.trig-subst»		(to "trig-subst")
# «.2015.2-C2-P1»	(to "2015.2-C2-P1")
# «.2015.2-C2-P2»	(to "2015.2-C2-P2")
# «.2016.1-C2-P1»	(to "2016.1-C2-P1")
# «.foci»		(to "foci")
# «.bel-6-11»		(to "bel-6-11")
# «.2016.1-GA-P2»	(to "2016.1-GA-P2")
# «.2016.1-C2-P2»	(to "2016.1-C2-P2")
# «.2016.1-GA-VR»	(to "2016.1-GA-VR")
# «.2016.1-C2-VR»	(to "2016.1-C2-VR")
# «.2016.1-C2-VS»	(to "2016.1-C2-VS")
# «.2016.2-GA-P1»	(to "2016.2-GA-P1")
# «.2016.2-C2-P1»	(to "2016.2-C2-P1")
# «.2016.2-C2-P2»	(to "2016.2-C2-P2")
# «.2017.1-GA-P1»	(to "2017.1-GA-P1")
# «.2017.1-GA-P2»	(to "2017.1-GA-P2")
# «.2017.1-GA-VR»	(to "2017.1-GA-VR")
# «.2017.1-C2-P1»	(to "2017.1-C2-P1")
# «.2017.1-C2-P2»	(to "2017.1-C2-P2")
# «.2017.1-C2-VS»	(to "2017.1-C2-VS")
# «.2017.2-C2-P2»	(to "2017.2-C2-P2")



# (find-angg ".emacs" "ipython")
# (find-esgrep "grep --color -niH -e ipython *.e")
# (find-esgrep "grep --color -niH -e sympy *.e")
# (find-es "python" "ipython")
# (find-es "sympy" "tutorial")


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import apart
from sympy import together
together(1/x + 1/y + 1/z)
together(apart((x+1)/(x-1), x), x)
together(apart(1/( (x+2)*(x+1) ), x), x)

apart((x+1)/(x**2 + x - 20), x)
apart((x**3)/(x**2 + x - 20), x)

together(1/(x-2) + 1/(x+5))
together(3/(x-2) + 4/(x+5))
together(3/(x-2) - 2/(x-3) + 4/(x+5))
together(3/(x-2) - 2/(x-3) + 4/(x+5)).expand()

((x-2)      *(x+5)).expand()
((x-2)*(x-3)      ).expand()
((x-2)*(x-3)*(x+5)).expand()
together(4/(x-2) + 1/(x-3) + 5/(x+5)).expand()

(4*(x**2 + 2*x - 15) + 1*(x**2 + 3*x - 10) + 5*(x**2 - 5*x + 6)).expand()

((2 * x**2 + 3 * x + 4) * (5 * x**2 - 
x**2


((x**2 + 2 * x + 3) * (x**2 - 2 * x + 1)).expand()
((x**2 + 2 * x + 3) * (x**2 - 2 * x + 1) + (4*x - 3)).expand()


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
s = Symbol("s")
integrate(s**3 / sqrt(1 - s**2), s)
integrate(s**3 / sqrt(1 - s**2), (s, -1, 1/2))
arccos(1/2)
arcsin(1/2)

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# from sympy import diff, Symbol, sin, tan
x = Symbol('x')
diff(atan(x), x)
diff(asec(x), x)

diff(sin(2*x), x)
diff(tan(x), x)

integrate(1/(x**2 + 1), x)



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Rational
R = Rational
A = Matrix([1, 1])
P = Matrix([R(8, 5), R(1, 5)])
A - P



#####
#
# Testing trigonometric substitutions
# 2016mar23
#
#####

# «trig-subst» (to ".trig-subst")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# from sympy.mpmath import *
from sympy import *

c, s, t, th, a, b = symbols("c,s,t,th,a,b")
trigs0 = lambda f: lambda s: f(s, sqrt(1 - s**2))
trigt0 = lambda f: lambda t: f(s, sqrt(1 - t**2))
trigz0 = lambda f: lambda z: f(z, sqrt(z**2 - 1))
trigs1 = lambda f: lambda th: f(sin(th), cos(th)) * sin(th)
trigt1 = lambda f: lambda th: f(tan(th), sec(th)) * (tan(th**2 + 1))
trigz1 = lambda f: lambda th: f(sec(th), tan(th)) * sec(th) * tan(th)

trigs0i = lambda f, a, b: integrate(trigs0(f)(s), (s, a, b))
trigt0i = lambda f, a, b: integrate(trigt0(f)(t), (t, a, b))
trigz0i = lambda f, a, b: integrate(trigz0(f)(z), (z, a, b))
trigs1i = lambda f, a, b: integrate(trigs1(f)(th), (th, asin(a), asin(b)))
trigt1i = lambda f, a, b: integrate(trigt1(f)(th), (th, atan(a), atan(b)))
trigz1i = lambda f, a, b: integrate(trigz1(f)(th), (th, asec(a), asec(b)))

trigs0I = lambda f, a, b: Integral(trigs0(f)(s), (s, a, b))
trigt0I = lambda f, a, b: Integral(trigt0(f)(t), (t, a, b))
trigz0I = lambda f, a, b: Integral(trigz0(f)(z), (z, a, b))
trigs1I = lambda f, a, b: Integral(trigs1(f)(th), (th, asin(a), asin(b)))
trigt1I = lambda f, a, b: Integral(trigt1(f)(th), (th, atan(a), atan(b)))
trigz1I = lambda f, a, b: Integral(trigz1(f)(th), (th, asec(a), asec(b)))

trigs0I(lambda s, c: s**2, a, b) 
trigs1I(lambda s, c: s**2, a, b) 

trigz0I(lambda z, t: t / z**3, a, b) 
trigz1I(lambda z, t: t / z**3, a, b) 

trigs0i(lambda s, c: 2, 0, 1)
trigt0i(lambda t, z: 2, 0, 1)
trigz0i(lambda z, t: 2, 0, 1)

# http://docs.sympy.org/0.7.2/modules/mpmath/functions/trigonometric.html?highlight=atan#asec
# http://docs.sympy.org/0.7.6/modules/mpmath/functions/trigonometric.html?highlight=asec
# http://docs.sympy.org/0.7.6/modules/mpmath/basics.html?highlight=mpmath
asec(1)




#####
#
# 2015.2-C2-P1
# 2016mar23
#
######

# «2015.2-C2-P1» (to ".2015.2-C2-P1")
# (find-angg "LATEX/2015-2-C2-P1.tex")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# Questao 1:
a = Symbol("a")
integrate(x**2 * cos(a*x), x)
integrate(x**2 * cos(2*x), (x, 0, pi))

# Questao 2:
integrate(x**3 / (x**2 + x - 20), x)

# Questao 3:
# (find-es "sympy" "numerical-integration")
from sympy.mpmath import *
integrate(sqrt(z**2 - 1) / z**3, z)

fz1 = lambda z:  sqrt(z**2 - 1) / z**3
ft1 = lambda th: tan(th)**2 / sec(th**2)
ft1 = lambda th: (1 - cos(2*th)) / 2
intz = lambda fz, za, zb: quad(fz, [za, zb])
intt = lambda ft, za, zb: quad(ft, [arcsec(za), arcsec(zb)])
intz(fz1, 2, 3)
intz(ft1, 2, 3)






#####
#
# 2015.2-C2-P2
# 2016mar23
#
######

# «2015.2-C2-P2» (to ".2015.2-C2-P2")
# (find-angg "LATEX/2015-2-C2-P2.tex")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
S = exp(-x) * sin(2*x)
C = exp(-x) * cos(2*x)
diff(C, x)
diff(S, x)
diff(diff(C, x), x)





* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
diff(x**3, x)
diff(sec(x), x)
diff(tan(x), x)



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
po = ((x-5)/5)**2 + ((y-6)/4)**2 - 1
po
(po*400).expand()




* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import apart
from sympy import together
together(1/x + 1/y + 1/z)
apart(x / (x**2 + x - 6), x)
apart(1 / (x**2 + x - 6), x)




#####
#
# 2016.1: Cálculo 2, P1, gabarito
# 2016jul27
#
#####

# «2016.1-C2-P1»    (to ".2016.1-C2-P1")
# (find-angg       "LATEX/2016-1-C2-P1.tex")
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf")
# (find-es "python" "tuples")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
s, th = symbols("s th")
def differenc(body, xab):
  return body.subs(xab[0], xab[2]) - body.subs(xab[0], xab[1])
def differen2(body, xab):
  return (body.subs(xab[0], xab[2]), body.subs(xab[0], xab[1]))
R = Rational


# 1:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 3)
# Obs: revisão ok, e a minha solução é melhor que a do sympy.
#
# O intervalo que nos interessa é onde tan(th) não é infinito,
# que é onde sen(th)/cos(th) não é infinito,
# que é onde cos(th) > 0,
# que é onde -pi/2 < th < pi/2.
#
expr1 = tan(th)
integrate(tan(th), th, manual=True)
integrate(tan(th), th)
`integrate(tan(th), th)`
Expr1 = -log(sin(th)**2 - 1)/2     # SymPy's solution (with manual=False)
Expr2 = -log(abs(cos(th)))         # my solution
Expr1
Expr2
a, b = 0.1, 0.2
integrate(expr1, (th, a, b))
differenc(Expr1, (th, a, b))
differenc(Expr2, (th, a, b))
differen2(Expr1, (th, a, b))       # SymPy's solution has complex numbers
differen2(Expr2, (th, a, b))       # my solution has everything real



# 2:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 3)
# Obs: ainda não revisei.
#
integrate(x**-4, x)
integrate(x**-4, (x, 1, 2))            # small
integrate(x**-4, (x, -1, -1/1000000))  # big
integrate(x**-4, (x, 1/1000000, 1))    # big
integrate(x**-4, (x, 1/1000000, 2))    # big + small


# 3:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 3)
# Obs: revisão ok.
#
ee, en, cc, ss = symbols("ee en cc ss")
(ee + 1/ee)**4
((ee + 1/ee)**4).expand()
((ee + 1/ee)**4).expand() / 16
(((ee + 1/ee)**4).expand() / 16).subs(ee, cos(th) + I*sin(th))
(((ee + 1/ee)**4).expand() / 16).subs(ee, cos(th) + I*sin(th)).subs(th, 0.1)

expr0 = cos(th)**4
expr1 = ((ee + 1/ee)**4 / 16).expand()
expr2 = ((ee +   en)**4 / 16).expand()
expr3 = expr2.subs(ee, cos(th) + I*sin(th)).subs(en, cos(th) - I*sin(th))
expr4 = R(1,8) * cos(4*th)  +  R(1,2) * cos(2*th)  +  R(3,8)
expr0
expr1
expr2
expr3
expr4

a = 0.1
a = 0.2
expr0.subs(th, a).expand()
expr1.subs(th, a).expand()
expr2.subs(th, a).expand()
expr3.subs(th, a).expand()
expr4.subs(th, a).expand()
integrate (expr4, th)
`integrate(expr4, th)`
Expr4 = 3*th/8 + sin(2*th)/4 + sin(4*th)/32
Expr4

expr0
expr4
integrate (expr0, th, manual=True)
integrate (expr0, th)
`integrate(expr0, th)`
integrate (expr4, th)
`integrate(expr4, th)`
Expr4

a, b = 0.1, 0.2
integrate(expr0, (th, a, b))
integrate(expr4, (th, a, b))
differenc(Expr4, (th, a, b))



# 4:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 3)
# Obs: revisão ok.
#
apart    (x**2 / (x**2 + x - 2), x)
integrate(x**2 / (x**2 + x - 2), x)


# 5:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 4)
# Obs: revisão ok.
#
integrate(x * exp(x) * cos(x), x)


# 6:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 4)
from sympy.mpmath import quad
# from sympy.mpmath import *

expr1x  = sqrt(4 - x**2)
expr1s  = 4 * sqrt(1 - s**2)
expr1th = 4 * sqrt(1 - sin(th)**2) * cos(th)
expr2th = 4 * cos(th)**2
expr3th = 4 * (1 + cos(2*th))/2
Expr3th = 4 * (th/2 + sin(2*th)/4)
Expr4th = 2*th + sin(2*th)
Expr4s  = Expr4th.subs(th, asin(s))
Expr4x  = Expr4s .subs(s,  x/2)

Expr3th
Expr4th
Expr4s
Expr4x

lamb1th = lambda th: 4 * sqrt(1 - sin(th)**2) * cos(th)
lamb1s  = lambda s:  4 * sqrt(1 - s**2)
lamb1x  = lambda x:  sqrt(4 - x**2)

a,   b = 0.1, 0.2
sa, sb = a/2, b/2
ta, tb = asin(sa), asin(sb)
integrate (expr1x,  (x,  a, b))
integrate (expr1s,  (s,  a/2, b/2))
integrate (expr1s,  (s,  sa,  sb))
#integrate(expr1th, (th, ta,  tb))
quad      (lamb1th,      [ta, tb])
quad      (lamb1s,       [sa, sb])
quad      (lamb1x,       [a,   b])
quad      (lamb1x,       [a,   b])
differenc (Expr4th, (th, ta,  tb))
differenc (Expr4s,  (s,  sa,  sb))
differenc (Expr4x,  (x,  a,    b))

integrate (expr1x,  (x,  0, 1))




# 7:
# (find-xpdfpage "~/LATEX/2016-1-C2-P1.pdf" 4)
# Obs: revisão ok.
#
integrate(  exp(x) - 1,  (x, 1, 2))
integrate(-(exp(x) - 1), (x, -1, 1))
integrate(  exp(x) - 1,  (x, -1, 2))





#####
#
# Converting equations on foci (with sqrts) to polynomials
# 2016jul27
#
#####

# «foci» (to ".foci")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

# Consequences of sqrt(A) + sqrt(B) = C:
# (gaq 52)
A = 25
B = 25
C = 10
( sqrt(A) + sqrt(B),     C)
((sqrt(A) + sqrt(B))**2, C**2)
(A + 2*sqrt(A*B) + B,    C**2)
(    2*sqrt(A*B),        C**2 - A - B)
(   (2*sqrt(A*B))**2,   (C**2 - A - B)**2)
(4*A*B, (C**2 - A - B)**2)
(4*A*B, C**4 - 2*A*C**2 - 2*B*C**2 + A**2 + 2*A*B + B**2)
(0,     C**4 - 2*A*C**2 - 2*B*C**2 + A**2 - 2*A*B + B**2)
(0,     C**2 * (C**2 - 2*A - 2*B) + (A-B)**2)
(0,     C**2 * (C**2 - 2*(A+B))   + (A-B)**2)

A = (x-3)**2 + y**2
B = (x+3)**2 + y**2
C = 10
(       C**2 * (C**2 - 2*(A+B))   + (A-B)**2).expand()
((A+B).expand(), (A-B).expand(),   ((A-B)**2).expand())


# Consequences of sqrt(A) - sqrt(B) = C:
# (gaq 54)
#
A = 100
B = 64
C = 2
( sqrt(A) - sqrt(B),     C)
((sqrt(A) - sqrt(B))**2, C**2)
(A - 2*sqrt(A*B) + B,    C**2)
(   -2*sqrt(A*B),        C**2 - A - B)
(  (-2*sqrt(A*B))**2,   (C**2 - A - B)**2)
(4*A*B, (C**2 - A - B)**2)
(4*A*B, C**4 - 2*A*C**2 - 2*B*C**2 + A**2 + 2*A*B + B**2)
(0,     C**4 - 2*A*C**2 - 2*B*C**2 + A**2 - 2*A*B + B**2)
(0,     C**2 * (C**2 - 2*A - 2*B) + (A-B)**2)
(0,     C**2 * (C**2 - 2*(A+B))   + (A-B)**2)

A = (x-3)**2 + y**2
B = (x+3)**2 + y**2
C = 2
(       C**2 * (C**2 - 2*(A+B))   + (A-B)**2).expand()
((A+B).expand(), (A-B).expand(),   ((A-B)**2).expand())


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# http://docs.sympy.org/0.7.2/tutorial.html#algebraic-equations
solve(t + 1/t - 2, t)
solve(t + 1/t - 3, t)
solve(t + 1/t - 4, t)
solve(t + 1/t - 5, t)
solve(t + 1/t - x, t)
solve(t + 1/t - 3, t)[1]




#####
#
# Lista 6 da Bel, problema 11: interseção de parábolas
# 2016jul27
#
#####

# «bel-6-11» (to ".bel-6-11")
# (gal6 2)

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

pol4 = x**4 - 6 * x**2 - x + 10
factor(pol4)
solve([y == x**2, x == (y-3)**2 +1])




#####
#
# 2016.1: GA, P2
# 2016jul27
#
#####

# «2016.1-GA-P2» (to ".2016.1-GA-P2")
# (find-es "sympy" "tut-linear-alg")
# (find-es "sympy" "matrices")
# (find-sympytutfile "matrices.rst" "transpose")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
proj2((3, 1), (x, y))



# Questão 2a
# (find-xpdfpage "~/LATEX/2016-1-GA-P2.pdf")
#
F    = M([R(1,2), 0])
dF2  = lambda P: norm22(M([P[0], P[1]]) - F)    # d(P,F)^2
dd2  = lambda P: (P[0]-2)**2                    # d(P,d)^2
ddd  = lambda P: dd2(P) - 4*dF2(P)              # d(P,d)^2 - 4*d(P,F)^2
dddd = lambda P: (dd2(P), 4*dF2(P))             # (d(P,d)^2, 4*d(P,F)^2)

dd2((x,y))**2
dF2((x,y))
dddd((x,y))
dddd((-1,0)), dddd((1,0))
dddd((0,y)),  dddd((0,-y))
ddd((0,y)),   ddd((0,-y))
solve(ddd((0,y)), y)
myy = solve(ddd((0,y)), y)[1]
myy = sqrt(3) / 2
myy
dddd((0,myy)),  dddd((0,-myy))

# 2b
#
F    = M([0, 0])
dF2  = lambda P: norm22(M([P[0], P[1]]) - F)    # d(P,F)^2
dd2  = lambda P: (P[0]-3)**2                    # d(P,d)^2
ddd  = lambda P: dd2(P) - 4*dF2(P)              # d(P,d)^2 - 4*d(P,F)^2
dddd = lambda P: (dd2(P), 4*dF2(P))             # (d(P,d)^2, 4*d(P,F)^2)

solve(ddd((x,0)), x)
solve(ddd((-1,y)), y)
myy = sqrt(3)
dddd((-3,0)), dddd((1,0))
dddd((-1,myy)),  dddd((-1,-myy))




# Questão 4
# (find-xpdfpage "~/LATEX/2016-1-GA-P2.pdf")
#
piz    = lambda x, y: 10 + 2*x - 3*y       # z such that     (x,y,z) in pi
pi0z   = lambda x, y:      2*x - 3*y       # z such that \vec(x,y,z) || pi
pixyz  = lambda x, y, z: piz(x, y) - z     # zero if (x,y,z) in pi
piP    = lambda P: pixyz(P[0], P[1], P[2]) # zero if P in pi
pin    = M([2, -3, -1])                    # a vector that is normal to pi
A1, v1 = M([2, 1, piz(2,1)]), M([1,  2, pi0z(1, 2)])
A2, v2 = M([1, 2, piz(1,2)]), M([3, -1, pi0z(3,-1)])
A3, v3 = M([2, 3, piz(2,3)]), pin
r1t = lambda t: A1 + t*v1
r2t = lambda t: A2 + t*v2
r3t = lambda t: A3 + t*v3

P = r3t(1)                                 # ponto P do enunciado: P=(4,0,4)
A4, v4 = P, pin
r4t = lambda t: P + t*pin
r4t(t)
piP(r4t(t))
solve(piP(r4t(t)), t)

r1t(t)                  # parametrização da reta r_1 : (2+t, 1+2t, 11-4t)
r2t(t)                  # parametrização da reta r_2 : (1+3t, 2-t, 6+9t)
(r1t(0), r1t(1)-r1t(0)) # parametrização da reta r_1 : (2, 1, 11) + t(1, 2, -4)
(r2t(0), r2t(1)-r2t(0)) # parametrização da reta r_2 : (1, 2,  6) + t(3, -1, 9)
pixyz(x, y, z)          # equação do plano pi:         2x - 3y - z + 10 = 0

r1t(0), r1t(1), piP(r1t(0)), piP(r1t(1))
r2t(0), r2t(1), piP(r2t(0)), piP(r2t(1))

st(t)
st(1)                   # ponto P:   (4, 0, 4)
st(0), piP(st(0))       # ponto P':  (2, 3, 5)
st(-1)                  # ponto P'': (0, 6, 6)



# Transferir pra outro lugar:

t1, t2 = symbols('t1 t2')
#
solve(r1t(t1) - r2t(t2))
solve(r1t(t1) - r2t(t2), [t1, t2])
sols = solve(r1t(t1) - r2t(t2), [t1, t2])             # where r1 meets r2
#
r1t(t1), r2t(t2)
r1t(t1) -r2t(t2)
vprod(r1t(t1)-r2t(t2), pin)
sols = solve(vprod(r1t(t1)-r2t(t2), pin), [t1, t2])   # where r1 is closer to r2
#
sols
type(sols)
sols[t1], sols[t2]
B1, B2 = r1t(sols[t1]), r2t(sols[t2])
B1, B2





#####
#
# 2016.1: C2 P2
# 2016aug01
#
####

# «2016.1-C2-P2» (to ".2016.1-C2-P2")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

# Questão 1
# (find-xpdfpage "~/LATEX/2016-1-C2-P2.pdf")

D = symbols("D")
((2+3*I) * (2-3*I)).expand()
a, b = -2, 0
a, b = -2, 3
((D - (a+b*I)) * (D - (a-b*I))).expand()
a, b =  3, 4
((D - (a+b*I)) * (D - (a-b*I))).expand()




# Questão 3
eq = f(x).diff(x) - f(x) + x
eq
dsolve(eq, f(x))


# Questão 3
# (find-xpdfpage "~/LATEX/2016-1-C2-P2.pdf")
# (find-es "sympy" "dsolve")
# (find-es "sympy" "integration")

F = 2*x + 3*x*y**2 - y**3
Fx = F.diff(x)
Fy = F.diff(y)
Fy, Fx


eq = Fy.subs(y, f(x)) * f(x).diff(x) + Fx
eq

Fx = 2 + 3*f(x)**2
Fy = 6*x*f(x) - 2*f(x)
eq = Fy * f(x).diff(x) + Fx
eq
dsolve(eq, f(x))
dsolve(eq, f(x), hint="1st_exact")

x0, x1, y0, y1 = symbols('x0 x1 y0 y1')
Fx.subs(f(x), 0)
integrate(Fx.subs(f(x), 0), (x, 0, x1))




#####
#
# 2016.1: GA VR
# 2016aug01
#
#####

# «2016.1-GA-VR»    (to ".2016.1-GA-VR")
# (find-angg       "LATEX/2016-1-GA-VR.tex")
# (find-xpdfpage "~/LATEX/2016-1-GA-VR.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
V = lambda a,b,c: M([a,b,c])

# Questão 1
pin  = V(1,1,1)
eqpi = lambda P: sprod3(pin, P) - 4
A    = V(3,3,3)
B    = lambda t: V(2,3,4) + t*V(2,0,3)
B(2)
r2   = lambda u: A + u*(B(2)-A)
r2(0)
r2(1)
eqpi(r2(t))
eqpi(r2(-R(1,2)))
r2(-R(1,2))

# Questão 4
P  = V(4,4,4)
nn = V(1,2,4)
eqpi = lambda P: sprod3(P, nn) - 4
sol = solve(eqpi(P + t*nn), t)
t1  = sol[0]
P1  = P + t1*nn
t1, norm3(P1 - P), P1

# Questão 4
eq1 = x/3 - (y-2)**2
eq2 = eq1.subs(y, 2*x)
eq1, eq2
sols = solve(eq2, x)
x1, x2 = sols[0], sols[1]
y1, y2 = 2*x1, 2*x2
eq1.subs(x, x1).subs(y, y1)
eq1.subs(x, x2).subs(y, y2)
((x1, y1), (x2, y2))



#####
#
# 2016.1: C2 VR
# 2016aug01
#
#####

# «2016.1-C2-VR»    (to ".2016.1-C2-VR")
# (find-angg       "LATEX/2016-1-C2-VR.tex")
# (find-xpdfpage "~/LATEX/2016-1-C2-VR.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questão 1a:
expr = x**4 * ln(x)
expr
Expr = integrate(expr, x, manual=True)
Expr
integrate(expr, (x, 2, 3))
differenc(Expr, (x, 2, 3))

# Questão 1b:
expr = x**3 * sqrt(1 - x**2)
expr
Expr = integrate(expr, x, manual=True)
Expr
Expr2 = (3 * x**4 - x**2 - 2) / 15 * sqrt(1 - x**2)
Expr2
Expr.equals(Expr2)

# Questão 1c:
apart    (x**2 / (x**2 - x - 6), x)
integrate(x**2 / (x**2 - x - 6), x)


# Questão 2:
# (find-es "sympy" "dsolve")
# (find-es "sympy" "Eq")
f = Function('f')
eq = f(x).diff(x, x) - f(x).diff(x) + 6*f(x)
eq = f(x).diff(x, x) - f(x).diff(x) - 6*f(x)
eq
dsolve(eq)
`dsolve(eq)`
a, b = symbols('a b')
g  = a*exp(-2*x) + b*exp(3*x)
gg = g.diff(x)
g0 = g.subs(x, 0)
g1 = g.subs(x, 1)
g0, g1
solve((g0, g1-1), [a, b])


# Questão 3:
f = Function('f')
eq = f(x).diff(x) + 2*(x+3)/f(x)
eq
dsolve(eq, f(x))
sol = sqrt(2) * sqrt(a - (x+3)**2).expand()
sol
expr = sol.diff(x) + 2*(x+3)/sol
expr
expr.subs(a, 20)
expr.subs(a, 20).equals(0)
# (find-sympytutfile "gotchas.rst" "a.equals(b)")

sol.subs(x, 0)
sol.subs(x, 0).subs(a, 10)
sol.subs(x, 0).subs(a, 59)
sol           .subs(a, 59)
sol           .subs(a, 59).subs(x, 0)





#####
#
# 2016.1: C2 VS
# 2016aug08
#
#####

# «2016.1-C2-VS» (to ".2016.1-C2-VS")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questão 1a
apart    (x**3 / (x**2 - 4), x)
integrate(x**3 / (x**2 - 4), x, manual=True)
expr1 = x**3 / (x**2 - 4)
expr2 = apart(expr1)
integrate(expr1, x)
integrate(expr2, x)

# Questão 1b
expr1 = 1 / (x * sqrt(x**2 - 1))
integrate(expr1, x, manual=True)

# Questão 1c
integrate(x**2 - 1, x)
integrate(x**2 - 1, (x, -2, -1))
integrate(1 - x**2, (x, -1,  1))
integrate(x**2 - 1, (x,  1,  2))



# Questão 2a:
D = symbols("D")
a, b =  -1, 2
((D - (a+b*I)) * (D - (a-b*I))).expand()
f = Function('f')
eq = f(x).diff(x,x) + 2*f(x).diff(x) + 5*f(x)
eq
dsolve(eq, f(x))

# Questão 2b:
a, b = symbols("a b")
f1 = cos(2*x) * exp(-x)
f2 = sin(2*x) * exp(-x)
f3 = a * f1 + b * f2
f3
cond1 = f3        .subs(x, 0)
cond2 = f3.diff(x).subs(x, 0) - 1
solve((cond1, cond2), (a, b))





#####
#
# 2016.2: GA P1
# 2016nov16 / 2016nov21
#
#####

# «2016.2-GA-P1» (to ".2016.2-GA-P1")
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")
# (find-es "sympy" "tut-linear-alg")
# (find-es "sympy" "solve")
# (find-LATEX "2016-2-GA-algebra.tex" "parametrizadas")
# (gaap 14)
# (find-LATEXfile "2016-2-GA-P1.tex")
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
from sympy import *
t,u = symbols('t u')

# Questão 2b:
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")
# (find-es "sympy" "Eq")

rt = M([1,2]) + t*M([3,4])              # [3*t+1, 4*t+2]
rt
eq_xt = Eq(x, rt[0])
eq_xt
eq_tx = Eq(t, solve(eq_xt, t)[0])
eq_tx
eq_tx.rhs
rx = rt.subs(t, eq_tx.rhs)
rx
eq_ryx = Eq(y, rx[1])
eq_ryx

a      = -R(3,4)
eq_syx = Eq(y, 5 + a*x)
eq_syx
sol_xy = solve([eq_ryx, eq_syx], [x,y])
sol_xy                                  # (x,y) = (52/25, 86/25) = (2.08,3.44)

eqs = [Eq(x, rt[0]), Eq(y, rt[1]), Eq(y, 5 + a*x)]
eqs
sols = solve(eqs, [x, y, t])            # (x,y) = (52/25, 86/25), t = 9/25
sols

eq_x   = Eq(eq_ryx.rhs, eq_syx.rhs)
eq_x
solx   = solve(eq_x)[0]
solx
eq_ryx.subs(x, solx)
eq_syx.subs(x, solx)
soly = solve(syx.subs(x, solx), y)[0]
soly

solx, soly                               # (x,y) = (52/25, 86/25)
solve(ryx, x)
solve(ryx, y)

eq_xt
eq_tx
Eq(eq_xt.lhs - eq_tx.lhs, eq_xt.rhs - eq_tx.rhs)

# Garbage:
a = symbols('a')
eq1 = Eq(2*x + 3*y + 4*a, 0)
eq2 = eq1.subs(x, 10).subs(y, 20)
eq1
eq2
solve(eq2, a)[0]



# Questão 4:
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")
# (find-es "sympy" "Eq")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
a    = R(3,4)
den  = drPdenom(a)                           # sqrt(1+a**2) --> 5/4
ry   = lambda x:   1+a*x                     # r(x,ry(x)) always belongs to r
dxyr = lambda x,y: (y-ry(x))/den             # d((x,y),r)   (without the "| |")
st   = lambda t:   V(0,1) + t*V(2,1)         # st(t) always belongs to s
dtr  = lambda t:   dxyr(st(t)[0], st(t)[1])  # d(st(t),r)   (without the "| |")
dxyr(0,3)                                   # 4a: d((0,3),r) == 8/5
dxyr(R(5,3),3)                                   # 4a: d((0,3),r) == 8/5
dtr(0)
dtr(1)
dtr(t)
solt1 = solve(Eq(dtr(t),  1), t)[0]          # t such that d(st(t),r) ==  1
solt2 = solve(Eq(dtr(t), -1), t)[0]          # t such that d(st(t),r) == -1
solt1, solt2
st(solt1)                                   # 4b: P1 = (-5,-3/2)
st(solt2)                                    #    P2 = ( 5, 7/2)
#
dxyr(0,y)
soly1 = solve(Eq(dxyr(0,y),  1), y)[0]
soly2 = solve(Eq(dxyr(0,y), -1), y)[0]
soly1
soly2
Eq(y, soly1 + R(3,4)*x)                     # 4c: r':  y = (3/4)*x + 9/4
Eq(y, soly2 + R(3,4)*x)                     #     r'': y = (3/4)*x - 1/4



# Questão 5:
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")
# (find-es "sympy" "Eq")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

makepolyC = lambda x0,y0,R: (x-x0)**2 + (y-y0)**2 - R**2
polyC  = makepolyC(0, 5, 5)
polyCC = makepolyC(1, 0, 1)
polyr  = (polyC - polyCC).expand()
polyC
polyCC
polyr
eqx = polyC.subs(y, solve(polyr, y)[0])
eqx
solve(eqx, x)
solx  = solve(eqx, x)[1]
polyy = polyr.subs(x, solx)
solx
polyy
soly = solve(polyy, y)[0]
soly

sols = solve([polyC, polyCC], [x,y])    # [(0, 0), (25/13, 5/13)]
sols








#####
#
# 2016.2: C2 P1
# 2016nov16 / 2016nov21
#
#####

# «2016.2-C2-P1» (to ".2016.2-C2-P1")
# (find-xpdfpage "~/LATEX/2016-2-C2-P1.pdf")
* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questão 1:
diff(atan(x), x)

# Questão 2:
F = x**-4
f = x**-3 / -3
differenc(f, (x, -1, R(-1,10)))
differenc(f, (x, -1, R(-1,100)))
differenc(f, (x, -1, R(-1,1000)))
integrate(F, (x, -1, R(-1,10)))
integrate(F, (x, -1, R(-1,100)))
integrate(F, (x, -1, R(-1,1000)))

# Questão 3:
L = 1 / (1-x)
R = 1 / (1+x)
integrate(L, x)
integrate(R, x)
integrate(L, (x, -1, 0))
integrate(R, (x, 0, 2))
integrate(L, (x, -1, 0)) + integrate(R, (x, 0, 2))

# Questão 4:
f = x**2 / (x**2 - 4*x - 5)
apart(f, x)
integrate(f, x)

# Questão 5a:
f = 1 / (1 + x**2)
integrate(f, x)

# Questão 5b:
f = x**2 / (1 - 4*x**2)
integrate(f, x)
f = x**2 / (1 - x**2)
integrate(f, x)

# Questão 6:
f = x * sin(4*x + 5)
integrate(f, x)




#####
#
# 2016.2: C2 P2
# 2017jan08
#
#####

# «2016.2-C2-P2» (to ".2016.2-C2-P2")
# (find-xpdfpage "~/LATEX/2016-2-C2-P2.pdf")
* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questão 2
f = Function('f')
eq = f(x).diff(x) - sin(2*x) / sin(5*f(x))
eq
dsolve(eq, f(x))

h = R(5,2) * cos(2*x)
f = R(1,5) * acos(h)
f
f.diff(x)
f.diff(x) - sin(2*x) / sin(5*f)
sin(5*f)
sin(2*x) / sin(5*f)



# Questão 3
z = ln(x*y**2+3)
z.diff(x)
z.diff(y)

zx = (x*y**2) / (x*y**2+3) + ln(x*y**2+3) - y*sin(x)
zx
zy = (2*x**2*y) / (x*y**2+3) + ln(x*y**2+3) + cos(x)
zy
zx.diff(y)
zy.diff(x)
zx.diff(y) - zy.diff(x)

z = integrate(zx, x)
z
z.diff(y)
integrate(zy, y)



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
f = x**4 - 3 * x**2
f.diff()
f.diff(x)
f.diff(x,x)
f.diff(x,x,x)
f.diff(x,x,x,x)
f.diff()       .subs(x, 1)
f.diff(x)      .subs(x, 1)
f.diff(x,x)    .subs(x, 1)
f.diff(x,x,x)  .subs(x, 1)
f.diff(x,x,x,x).subs(x, 1)

eq = f(x).diff(x,x) + 2*f(x).diff(x) + 5*f(x)

2.5 * 2.5
(2 * 2)**3
(2.5 * 2.5)**3



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
together(2/(x+1) + 3/(x-2) - 4/(x+3))
together(2/(x+1) + 3/(x-2) - 4/(x+3)).expand()


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
expr = cos(x) + (1 + (sin(x)**2))
integrate(expr, x, manual=True)
integrate(1 / sin(x), x, manual=True)



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
integrate((2*x+3) * sin(4*x+5), x, manual=True)
integrate(x * sin(4*x+5), x, manual=True)




#####
#
# 2017.1: GA P1
# 2017jun29
#
#####

# «2017.1-GA-P1» (to ".2017.1-GA-P1")
# (find-xpdfpage "~/LATEX/2017-1-GA-P1.pdf")
# (find-es "sympy" "tut-linear-alg")
# (find-es "sympy" "solve")
# (find-LATEX "2016-2-GA-algebra.tex" "parametrizadas")
# (gaap 14)
# (find-LATEXfile "2016-2-GA-P1.tex")
# (find-xpdfpage "~/LATEX/2016-2-GA-P1.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
eq1 = R(4,5) * abs(4 - R(3,4)*x - y) - 1
eq2 = y - 2*x
solve([eq1, eq2])    # (1, 2), (21/11, 42/11)

from sympy import *
t,u = symbols('t u')



#####
#
# 2017.1: GA P2
# 2017jul16
#
#####

# «2017.1-GA-P2» (to ".2017.1-GA-P2")
# (find-LATEX "2017-1-GA-P2.tex")
# (find-xpdfpage "~/LATEX/2017-1-GA-P2.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
mym = M([[0, 1, -2], [1, 0, -2], [1, 1, -2]])
mym
det(mym)


# Questão 1
# (find-xpdfpage "~/LATEX/2017-1-GA-P2.pdf")
u = y - x/2
v = y + x/2
uu = V2(-1, .5)
vv = V2( 1, .5)
solve(V2(u,v))
solve(V2(u,v) - V(1,0))
solve(V2(u,v) - V(0,1))

uvtoxy = lambda u,v: u*uu + v*vv
uvtoxy(4,-2)    # -6,1
uvtoxy(1,-1)    # -2,0
uvtoxy(0, 0)    #  0,0
uvtoxy(1, 1)    #  0,1
uvtoxy(4, 2)    # -2,3

(u - v**2).subs(x, -2).subs(y, 3)
(u - v**2).subs(x, -2).subs(y, 3)


# Questão 3
A = (x-1)**2 + y**2
B = (x+1)**2 + y**2
C = 4
S = sqrt(A) + sqrt(B) - C
S

D = C**2 * (C**2 - 2*(A+B)) + (A-B)**2
D = D.expand()
D
D/192

S
S.subs(y,0)
S.subs(y,0).subs(x,2)
S.subs(y,0).subs(x,-2)
S.subs(x,0).subs(y,sqrt(3))

D.subs(y,0)
D.subs(y,0).subs(x,2)
D.subs(x,0).subs(y,sqrt(3))



D0 = C**2 - A - B - 2*sqrt(A*B)
D  = D0

# A,B,C = symbols('A B C')

D/192


solve(D.subs(y,0), x)




#####
#
# 2017.1: GA VR
# 2017jul18
#
#####

# «2017.1-GA-VR» (to ".2017.1-GA-VR")
# (find-LATEX "2017-1-GA-VR.tex")
# (find-xpdfpage "~/LATEX/2017-1-GA-VR.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questao 3:
t, aa  = symbols('t, aa')
nn, A  = V3(2,2,1), V3(0,0,4)
r0, rv = V3(1,2,3), V3(2,1,0)
s0, sv = V3(0,0,0), nn
r      = lambda t: r0+t*rv
s      = lambda t: s0+t*sv

# Questao 3a:
F = inter_plane_line(plane_from_nn_A(nn, A), r)
F                                                # (-2/3, 7/6, 3)

# Questao 3c:
H = inter_plane_line(plane_from_nn_A(nn, A), s)
H                                                # (8/9, 8/9, 4/9)

# Questao 3d:
dist_plane_P(nn, A, V3(0,0,0))                   # -4/3

# Questao 3e:
norm3(H)                                         # 4/3

# Questao 3f:
di = dist_plane_P(nn, A, V3(0,0,aa))
di                                               # aa/3 - 4/3
solve(di-1, aa)[0]                               # 7
solve(di+1, aa)[0]                               # 1
dist_plane_P(nn, A, V3(0,0,7))                   # 1
dist_plane_P(nn, A, V3(0,0,1))                   # -1

# Questao 3g:
inter_plane_line(plane_from_nn_A(nn, V3(0,0,7)), r)  # (1/3, 5/3, 3)
inter_plane_line(plane_from_nn_A(nn, V3(0,0,1)), r)  # (-5/3, 2/3, 3)

# Questao 3h:
dist_plane_P(nn, A, V3(0,0,10))                       # 2
dist_plane_P(nn, A, V3(0,0,-2))                       # -2
inter_plane_line(plane_from_nn_A(nn, V3(0,0,10)), r)  # (4/3, 13/6, 3)
inter_plane_line(plane_from_nn_A(nn, V3(0,0,-2)), r)  # (-8/3, 1/6, 3)









#####
#
# 2017.1: C2 P1
# 2017jul17
#
#####

# «2017.1-C2-P1» (to ".2017.1-C2-P1")
* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
ee = symbols('ee')

# Questão 1:
diff(atan(x), x)

# Questão 2:
f = x**(-4)
F = integrate(f, x)
G = integrate(f, (x, -1, -ee)) + integrate(f, (x, ee, 1)) 
G

# Questão 3:
fl = 1/(3-x)
fr = 1/(3+x)
integrate(fl, (x, -1, 0))
integrate(fr, (x,  0, 2))
integrate(fl, (x, -1, 0)) + integrate(fr, (x,  0, 2))

# Questão 4:
f = x**2 / (x**2 + 4*x - 5)
apart(f, x)
F = integrate(f, x)
F

# Questão 5:
f = x / (x**2 + 1)
F = integrate(f, x)
F

# Questão 6:
f = (cos(x)**4)
F = integrate(f, x)
F



#####
#
# 2017.1: C2 P2
# 2017jul18
#
#####

# «2017.1-C2-P2» (to ".2017.1-C2-P2")
# (find-angg "LATEX/2017-1-C2-P2.tex")
# (find-xpdfpage "~/LATEX/2017-1-C2-P2.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# (find-es "sympy" "tut-solve")

# Questao 1:
a,b = symbols("a,b")
f = Function('f')
eq = f(x).diff(x,x) - 5*f(x).diff(x) + 6*f(x)
dsolve(eq, f(x))
f1 = exp(2*x)
f2 = exp(3*x)
sol = a*f1 + b*f2
sol
cond0 = sol.subs(x, 0)
cond1 = sol.diff(x).subs(x, 0)
cond0
cond1
solve([cond0 - 1, cond1 - 0], [a, b])
solve([cond0 - 0, cond1 - 1], [a, b])
solve([cond0 - 2, cond1 - 3], [a, b])


# Questao 2:
# (find-es "sympy" "Function")
# (find-es "sympy" "Symbol")
f1,f2,f3,f4 = symbols('f1,f2,f3,f4', cls=Function)
D = symbols("D")
a, b =  -2, 3
((D - (a+b*I)) * (D - (a-b*I)))
((D - (a+b*I)) * (D - (a-b*I))).expand()
f = Function('f')
eq = f(x).diff(x,x) + 4*f(x).diff(x) + 13*f(x)
dsolve(eq, f(x))
f3 = cos(3*x) * exp(-2*x)
f4 = sin(3*x) * exp(-2*x)

f3 = Lambda(x, cos(3*x) * exp(-2*x))
f4 = Lambda(x, sin(3*x) * exp(-2*x))
f3
2*f3
Lambda(x, 2*f3(x))
f1.diff(x)
eq.subs(f, sin)
eq.subs(f, sin).expand()
eq.subs(f, f3).expand()
f = Lambda(x, x**2)


# Questao 3:
# (find-es "sympy" "Eq")
C1 = symbols("C1")

eq = f(x).diff(x) - x*exp(-f(x))
eq
dsolve(eq, f(x))
f1 = dsolve(eq, f(x)).rhs
f1
c = solve(f1.subs(x, 3) - 4)[0]
c
f2 = f1.subs(C1, c)
f2
f2.subs(x, 3)

f1.subs(C1, 9)
f1.subs(x, 3)




#####
#
# 2017.1: C2 VS
# 2017jul31
#
#####

# «2017.1-C2-VS» (to ".2017.1-C2-VS")
# (find-angg "LATEX/2017-1-C2-VS.tex")
# (find-xpdfpage "~/LATEX/2017-1-C2-VS.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
a,b = symbols('a,b')

# Questão 1:
f = x * sqrt(1 - x**2)
F = integrate(f, x)
f
F

# Questão 3:
f = x * sin(a*x + b)
F = integrate(f, x)
f
F

# Questão 4:
f = x / (x**2 + 1)
F = integrate(f, x)
f
F




#####
#
# 2017.2: C2 P2
# 2017dez14
#
#####

# «2017.2-C2-P2» (to ".2017.2-C2-P2")
# (find-angg "LATEX/2017-1-C2-P2.tex")
# (find-xpdfpage "~/LATEX/2017-2-C2-P2.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# (find-es "sympy" "tut-solve")

# Questao 1:
a,b = symbols("a,b")
f = Function('f')
eq = f(x).diff(x,x) + 4*f(x).diff(x) - 12*f(x)
dsolve(eq, f(x))
f1 = exp(-6*x)
f2 = exp( 2*x)
sol = a*f1 + b*f2
sol
cond0 = sol.subs(x, 0)
cond1 = sol.diff(x).subs(x, 0)
cond0
cond1
solve([cond0 - 1, cond1 - 0], [a, b])
solve([cond0 - 0, cond1 - 1], [a, b])
solve([cond0 - 4, cond1 - 5], [a, b])


# Questao 2:
# (find-es "sympy" "Function")
# (find-es "sympy" "Symbol")
f1,f2,f3,f4 = symbols('f1,f2,f3,f4', cls=Function)
D = symbols("D")
a, b =  -3, 2
((D - (a+b*I)) * (D - (a-b*I)))
((D - (a+b*I)) * (D - (a-b*I))).expand()
f = Function('f')
eq = f(x).diff(x,x) + 4*f(x).diff(x) + 13*f(x)
dsolve(eq, f(x))
f3 = cos(3*x) * exp(-2*x)
f4 = sin(3*x) * exp(-2*x)

f3 = Lambda(x, cos(3*x) * exp(-2*x))
f4 = Lambda(x, sin(3*x) * exp(-2*x))
f3
2*f3
Lambda(x, 2*f3(x))
f1.diff(x)
eq.subs(f, sin)
eq.subs(f, sin).expand()
eq.subs(f, f3).expand()
f = Lambda(x, x**2)


# Questao 3:
# (find-es "sympy" "Eq")
C1 = symbols("C1")
a,b = symbols("a,b")

eq = f(x).diff(x) - x**2 * exp(-3*f(x))
eq
dsolve(eq, f(x))
dsolve(eq, f(x))[0]
f1 = dsolve(eq, f(x))[0].rhs
f1
c = solve(f1.subs(x, 3) - 4)[0]
c
c = solve(f1.subs(x, a) - b)[0]
c
f2 = f1.subs(C1, c)
f2
f2.subs(x, 3)

f1.subs(C1, 9)
f1.subs(x, 3)















https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks
http://nbviewer.jupyter.org/github/lgiordani/blog_source/blob/master/pelican/content/notebooks/Python_3_OOP_Part_2__Classes_and_members.ipynb
https://www.youtube.com/watch?v=LmIwkA4_c6Q&feature=youtu.be
https://www.facebook.com/portalconfluencias/videos/539432586248223/
https://www.youtube.com/watch?v=hyByTc8OcCk&feature=share
https://www.facebook.com/groups/556513917890368/permalink/578195885722171/





#  Local Variables:
#  coding:               raw-text-unix
#  ee-delimiter-hash:    "\n#*\n"
#  ee-delimiter-percent: "\n%*\n"
#  ee-anchor-format:     "«%s»"
#  End: