Warning: this is an htmlized version!
The original is here, 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.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# 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.2-GA-VS»	(to "2017.2-GA-VS")
# «.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")
# «.2018.2-C2-P1»	(to "2018.2-C2-P1")
# «.2018.2-C2-P2»	(to "2018.2-C2-P2")
# «.2018.2-C2-P2-q2»	(to "2018.2-C2-P2-q2")
# «.2018.2-C2-P2-q4»	(to "2018.2-C2-P2-q4")
# «.2018.2-C2-VS»	(to "2018.2-C2-VS")
# «.2019.1-C2-P1»	(to "2019.1-C2-P1")
# «.2019.1-C2-P2»	(to "2019.1-C2-P2")
# «.2019.1-C2-VR»	(to "2019.1-C2-VR")
# «.2019.1-C2-VS»	(to "2019.1-C2-VS")
#
# «.2019.1-C3-P1»	(to "2019.1-C3-P1")
# «.2019.1-C3-VR»	(to "2019.1-C3-VR")
# «.2019.2-C3-P2»	(to "2019.2-C3-P2")
# «.2019.2-C3-VR»	(to "2019.2-C3-VR")
# «.2019.2-C3-VS»	(to "2019.2-C3-VS")

# «.2019.2-C2-P1»	(to "2019.2-C2-P1")
# «.2019.2-C2-P2»	(to "2019.2-C2-P2")
# «.2019.2-C2-VR»	(to "2019.2-C2-VR")
# «.2019.2-C2-VS»	(to "2019.2-C2-VS")
# «.2020.1-int-subst»	(to "2020.1-int-subst")
# «.2020.1-C2-MT1»	(to "2020.1-C2-MT1")
# «.2020.1-C2-P1»	(to "2020.1-C2-P1")
# «.2020.1-C2-P2»	(to "2020.1-C2-P2")
# «.2020.1-C3-P1»	(to "2020.1-C3-P1")
# «.2020.1-C3-P2»	(to "2020.1-C3-P2")
# «.watts-strogatz»	(to "watts-strogatz")
# «.bortolossi-5.5»	(to "bortolossi-5.5")
# «.perspective»	(to "perspective")
# «.2021.1-C3-P1»	(to "2021.1-C3-P1")
# «.2021.1-C2-P2»	(to "2021.1-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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/LATEX/2016-1-C2-P1.pdf" 4)
# Obs: revisão ok.
#
integrate(x * exp(x) * cos(x), x)


# 6:
# (find-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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.2: GA VS
# 2018jan19
#
#####

# «2017.2-GA-VS» (to ".2017.2-GA-VS")
# (find-LATEX "2017-2-GA-VS.tex")
# (find-pdf-page "~/LATEX/2017-2-GA-VS.pdf")

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

# Questao 1:
A, B, C, D = V3(0, 2, 2), V3(3, 3, 0), V3(4, 0, 4), V3(0, 4, 2)
AB  = B - A
AC  = C - A
pin  = - vprod(AB, AC) / 2         # pi_normal: (1, 7, 5)
pid  = sprod3(pin, A)              # pi_d = 24; a equação de pi é: 1x + 7y + 5z = 24
pieq = lambda P: sprod3(pin, P) - pid
rr   = lambda t: D + t*pin
E    = inter_plane_line(pieq, rr)  # E = (-14/75, 202/75, 48/75)
r    = lambda t: D + t*pin
F    = closest_line_P3(r, D)

pieq(V3(x, y, z))
pieq(A), pieq(B), pieq(C)
r(t)
E
F
pieq(E), vprod(E-D, pin)            # E in pi, DE // nn
vprod(F-D, pin), sprod3(F-D, pin)   # DF _|_ nn, DF // nn
D, F


pid  # (1, 7, 5)
A    #
sprod3(nn, A)


# 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-pdf-page "~/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-pdf-page "~/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-pdf-page "~/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)






#####
#
# 2018.2-C2-P1
# 2018dec08
#
#####

# «2018.2-C2-P1» (to ".2018.2-C2-P1")
# (find-LATEX "2018-2-C2-P1.tex" "gab-2")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
s,u,z = symbols("s,u,z")


# Questao 2
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 1)
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 2)
f  = 1 / ((s**2 - 1)**2)
fa = apart(f, s)
fa
Fa = integrate(fa, s)
Fa
integrate(1/(s+1)**2, s)
integrate(1/(s-1)**2, s)


# Questao 3
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 1)
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 3)
f = x**3 / (x**2 + 7*x + 12)
f
g = x - 7 + (37*x + 84) / ((x+3)*(x+4))
g
apart(f)
apart(g)
integrate(f, x)


# Questao 4
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 1)
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 3)
integrate((u+3)**4 / u**2, u)


# Questao 5
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 1)
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 3)
integrate(log(x), x)
integrate(x*log(x), x)





#####
#
# 2018.2-C2-P2
# 2018dec12
#
#####

# «2018.2-C2-P2» (to ".2018.2-C2-P2")
# (find-LATEX "2018-2-C2-P2.tex")

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

# «2018.2-C2-P2-q2» (to ".2018.2-C2-P2-q2")
a,b = symbols("a,b")
F = exp(3*x)
C = cos(4*x)
S = sin(4*x)
FC  = F*C
FC1 = diff(F*C, x)
FC2 = diff(F*C, x, x)
FC
FC1
FC2
diff(a*F*C + b*F*S, x)
diff(a*F*C + b*F*S, x)   .subs(a, 1).subs(b, 0)
diff(a*F*C + b*F*S, x, x).subs(a, 1).subs(b, 0)

# «2018.2-C2-P2-q4» (to ".2018.2-C2-P2-q4")

s,u,z = symbols("s,u,z")
s,u,z,dx,dy = symbols("s,u,z,dx,dy")
f = Function('f')

G = 2*x*y**3
H = 3 * (x**2 + 3) * y**2
diff(G, y)
diff(H, x)

F = y**3 * (x**2 + 3)
F
diff(F, x)
diff(F, x) - G
diff(F, y)
(diff(F, y) - H).subs(x, 42)
diff(F, x, y)
diff(F, y, x)
myeq = diff(F, x)*dx + diff(F, y)*dy
myeq
myeq = diff(F, x) + diff(F, y)*f(x).diff(x)
myeq
myeq2 = myeq.subs(y, f(x))
myeq2
dsolve(myeq2, f(x))





#####
#
# 2018.2-C2-VS
# 2018dec19
#
#####

# «2018.2-C2-VS» (to ".2018.2-C2-VS")
# (find-LATEX "2018-2-C2-VS.tex")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
t,th = symbols("t,th")
C = cos(th)
S = sin(th)
f = C**3 * S
integrate(C**3 * S, th)
integrate(C**3 * S**3, th)

E,Einv = symbols("E,Einv")
C = (E + Einv)/2
S = (E - Einv)/(2*I)
f = C**3 * S**3
expand(f)

zz = sqrt(t**2 + 1)
integrate(        zz**-1, t)
integrate(t     * zz**-1, t)
integrate(t**2  * zz**-1, t)
integrate(t**-1 * zz**-1, t)

f = 1 / (sqrt(4*x**2 + 9))
integrate(f, x)




#####
#
# 2019.1-C2-P1
# 2019jun04
#
#####

# «2019.1-C2-P1»  (to ".2019.1-C2-P1")
# (find-LATEX "2019-1-C2-P1.tex" "gab-2")
# (find-xpdfpage "~/LATEX/2019-1-C2-P1.pdf")
# (find-fline "~/2019.1-C2/" "20190623_c2_p1")
# (xz "~/2019.1-C2/20190623_c2_p1_gab_q1.jpg")
# (xz "~/2019.1-C2/20190623_c2_p1_gab_q2.jpg")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
s,u,z  = symbols("s,u,z")
t,th   = symbols("t,th")
E,Einv = symbols("E,Einv")

# Questao 1
# (c2p1p)
Sn = lambda n: (E**n - E**-n) / (2*I)
Cn = lambda n: (E**n + E**-n) /  2
expr = Sn(3)**2 * Cn(4)**2
expr
expr.expand()
expr = Cn(14)/-8 + Cn(8)/4 + Cn(6)/4 + Cn(2)/-8 - R(1,4)
expr
#
Sn = lambda n: sin(n*th)
Cn = lambda n: cos(n*th)
expr = Cn(14)/-8 + Cn(8)/4 + Cn(6)/4 + Cn(2)/-8 - R(1,4)
integrate(expr, th)

# Questao 2
# (xz "~/2019.1-C2/20190623_c2_p1_gab_q2.jpg")
expr = x * ln(2*x + 3)
integrate(expr, x)

# Questao 3
# (find-es "sympy" "trig-subst-questions")

S = sqrt(1 - x**2)
T = sqrt(x**2 + 1)
Z = sqrt(x**2 - 1)

integrate(x**3 * S**-3, x)
integrate(x**3 * S**-2, x)
integrate(x**3 * S**-1, x)
integrate(x**3 * S** 1, x)
integrate(x**3 * S** 2, x)
integrate(x**3 * S** 3, x)

integrate(x**2 * S**-3, x)
integrate(x**2 * S**-2, x)
integrate(x**2 * S**-1, x)    # bom
integrate(x**2 * S** 1, x)
integrate(x**2 * S** 2, x)
integrate(x**2 * S** 3, x)

integrate(x**2 * sqrt(4 - 9 * x**2)**-1, x)    # bom
integrate(x**2 * sqrt(1 -     x**2)**-1, x)

# Questao 4
# f = x**3 / (x**2 + 8*x + 12)
f = x**3 / (x**2 + 7*x + 12)
g = x - 7 + (37*x + 84) / ((x+3)*(x+4))
apart(f)
apart(g)
integrate(f, x)

apart(f)
integrate(f, x)
f
g = x - 7 + (37*x + 84) / ((x+3)*(x+4))
g
apart(f)
apart(g)
integrate(f, x)

# Questao 2
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 1)
# (find-pdf-page "~/LATEX/2018-2-C2-P1.pdf" 2)




#####
#
# 2019.1-C2-P2
# 2019jul04
#
#####

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

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
s,u,z = symbols("s,u,z")
s,u,z,dx,dy = symbols("s,u,z,dx,dy")
f = Function('f')

# Questão 1
eq = f(x).diff(x,x) + 8*f(x).diff(x) - 20*f(x)
eq
dsolve(eq, f(x))
sol = dsolve(eq, f(x)).rhs
sol
soll  = sol.diff(x)
soll
sol0  = sol .subs(x, 0)
soll0 = soll.subs(x, 0)
sol0, soll0
solC = solve([sol0 - 1, soll0 - 0])
solC
sol.subs(solC)
str(sol.subs(solC))

# 1a)   (D-2)(D+10)f
# 1b)   exp(2*x), exp(-10*x)
# 1c)   5*exp(2*x)/6 + exp(-10*x)/6

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

# Questao 2:
# (find-es "sympy" "linear-order2-complex")
# (find-es "sympy" "Function")
# (find-es "sympy" "Symbol")
f1,f2,f3,f4 = symbols('f1,f2,f3,f4', cls=Function)
D = symbols("D")
a, b =  -4, 3
((D - (a+b*I)) * (D - (a-b*I)))
((D - (a+b*I)) * (D - (a-b*I))).expand()
((D - (-4+3*I)) *  (D - (-4-3*I)))
((D - (-4+3*I)) *  (D - (-4-3*I))).expand()

eq = f(x).diff(x,x) + 8*f(x).diff(x) + 25*f(x)
f1 = exp((a+b*I)*x)
f2 = exp((a-b*I)*x)
f1
f2
dsolve(eq, f(x))

f3 = cos(3*x) * exp(-4*x)
f4 = sin(3*x) * exp(-4*x)
# eq.subs(f, f3)
# eq.subs(f(x), f3(x))

# 2a)   (D - (-4+3*I)) (D - (-4-3*I)) f
# 2b)   f1 = exp ((-4+3*I)*x),
#       f2 = exp ((-4-3*I)*x)
# 2c)   f3 = cos(3x) * exp(-4*x),
#       f4 = sin(3x) * exp(-4*x)


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

# Questão 3
f = Function('f')
g = (x**2 + 3) / (y+4)**5
g
g.subs(y, f(x))
myeq = f(x).diff(x) - g.subs(y, f(x))
myeq
dsolve(myeq, f(x))




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

# Questão 5
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
f = sin(x)
g = cos(x)
h = f - g
h.subs(x, 0)
h.subs(x, pi/4)
h.subs(x, R(5,4)*pi)
#
integrate(h, x)
integrate(h, (x, R(0,4)*pi, R(1,4)*pi))
A = integrate(h, (x, R(1,4)*pi, R(5,4)*pi))
B = integrate(h, (x, R(5,4)*pi, R(8,4)*pi))
A
B
A - B




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)







#####
#
# 2019.1-C2-VR
# 2019jul04
#
#####

# «2019.1-C2-VR» (to ".2019.1-C2-VR")
# (find-angg "LATEX/2019-1-C2-VR.tex")

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

# Questao 1
f = (x**3 + 4) / (x**2 - x - 20)
apart(f)

# Questao 2
solve(9 - 4*x**2, x)
a = -R(3,2)
b =  R(3,2)
f = sqrt(9 - 4*x**2)
f
integrate(f, x)



# Questao 3
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
s,u,z  = symbols("s,u,z")
t,th   = symbols("t,th")
E,Einv = symbols("E,Einv")
Sn   = lambda n: (E**n - E**-n) / (2*I)
Cn   = lambda n: (E**n + E**-n) /  2
expr = Sn(1)**6
expr
expr.expand()
expr2 = Cn(6)/-32 + R(3,16)*Cn(4) - R(15,32)*Cn(2) + R(5,16)
expr2
expr2 - expr.expand()
#
Sn = lambda n: sin(n*th)
Cn = lambda n: cos(n*th)
expr = Cn(6)/-32 + R(3,16)*Cn(4) - R(15,32)*Cn(2) + R(5,16)
integrate(expr, th)


g = x - 7 + (37*x + 84) / ((x+3)*(x+4))
apart(g)
integrate(f, x)

apart(f)
integrate(f, x)
f
g = x - 7 + (37*x + 84) / ((x+3)*(x+4))
g
apart(f)
apart(g)
integrate(f, x)









#####
#
# 2019.1-C2-VS
# 2019jul04
#
#####

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

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
f = x**3 * sqrt(1 - x**2)
integrate(f, x)






#####
#
# 2019.1-C3-P1
# 2019jun17
#
#####

# «2019.1-C3-P1» (to ".2019.1-C3-P1")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
F = exp(2) * sin(x*y)
F
F.diff(x)
F.diff(y)
F.diff(x,x)
F.diff(x,y)
F.diff(y,y)

F = (x-y) / (x+y)
F
F.diff(x)
F.diff(x).together()
F.diff(y)
F.diff(y).together()
F.diff(x,x)
F.diff(x,y)
F.diff(y,y)

# (find-es "sympy" "tut-solve")




#####
#
# 2019.1-C3-VR
# 2019jul09
#
#####

# «2019.1-C3-VR» (to ".2019.1-C3-VR")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
F = exp(x) * ln(x + 2*y)
F
F.diff(x)
F.diff(x,x)
F.diff(x,y)
F.diff(y)
F.diff(y,y)

G = Function('G')
h = Function('h')
F = G(x,y)/h(x)
F.diff(x)
F.diff(x,x)
F.diff(x,y)
F.diff(y)
F.diff(y,y)

F = sqrt(x**2 + y**2)
F
F.diff(x)
F.diff(x,x)
F.diff(x,y)
F.diff(y)
F.diff(y,y)




#####
#
# 2019.2-C3-P2
# 2019dec12
#
#####

# «2019.2-C3-P2» (to ".2019.2-C3-P2")
# (find-angg "LATEX/2019-1-C3-P2.tex")
# (find-pdf-page "~/LATEX/2019-1-C3-P2.pdf")

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

# Questao 2
# (find-pdf-page "~/LATEX/2019-1-C3-P2.pdf")
#
dt,m,ga = symbols("dt,m,ga")
t0      = 5
g       = 6 + dt
h       = 7 + m * dt
F       = 4 * (x-6)**2 + ga * (x-6) * (y-7) + 9 * (y-7)**2
F.subs(x, g).subs(y, h)
F.subs(x, g).subs(y, h).subs(dt, 1)
eq = F.subs(x, g).subs(y, h).subs(dt, 1).subs(ga, 12)
eq
solve(eq)

# Questao 1
# (find-pdf-page "~/LATEX/2019-1-C3-P2.pdf")
# (find-es "sympy" "lagrange-multipliers")
#
la = symbols('la')
F = x - (y - 1)**2
H = x**2 + 4*y**2 - 4

L = F - la*H
grad_F = M([F.diff(x), F.diff(y)])
grad_H = M([H.diff(x), H.diff(y)])
L_xyla = M([L.diff(x), L.diff(y), L.diff(la)])
L_xyla
L_xy = M([L.diff(x), L.diff(y)])
sol = solve(L_xy)
sol

sol = solve(L_xyla)
sol
grad_F.subs(sol)
grad_H.subs(sol)




#####
#
# 2019.2-C3-VR
# 2019dec13
#
#####

# «2019.2-C3-VR»    (to ".2019.2-C3-VR")
# (find-LATEX            "2019-2-C3-VR.tex")
# (find-pdf-page "~/LATEX/2019-2-C3-VR.pdf")

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

s = lambda k: sin(k * pi/6)
c = lambda k: cos(k * pi/6)
s(0), s(1), s(2), s(3), s(4), s(5), s(6)
c(0), c(1), c(2), c(3), c(4), c(5), c(6)

# (find-es "sympy" "lagrange-multipliers")
#
la = symbols('la')
F = x * (x-y)
F = x * (y - 1)
H = x**2 + 4*y**2 - 4
H = x**2 + y**2 - 4

L = F - la*H
grad_F = M([F.diff(x), F.diff(y)])
grad_H = M([H.diff(x), H.diff(y)])
L_xyla = M([L.diff(x), L.diff(y), L.diff(la)])
L_xyla
L_xy = M([L.diff(x), L.diff(y)])
solxy = solve(L_xy)
solxy

sol = solve(L_xyla)
sol
grad_F.subs(sol)
grad_H.subs(sol)




#####
#
# 2019.2-C3-VS
# 2019dec20
#
#####

# «2019.2-C3-VS»    (to ".2019.2-C3-VS")
# (find-LATEX            "2019-2-C3-VS.tex")
# (find-pdf-page "~/LATEX/2019-2-C3-VS.pdf")

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

# Questao 1
P  = M([cos(t), sin(2*t)])
Pd = P.diff(t)
P
Pd
M([P, Pd]).subs(t, pi)
M([P, Pd]).subs(t, aa)
M([P, Pd]).subs(t, R(1,2)*pi)

# Questao 3
# (find-es "sympy" "lagrange-multipliers")
#
la = symbols('la')
F = x-y
H = x**2 + 4*y**2 - 4

L = F - la*H
grad_F = M([F.diff(x), F.diff(y)])
grad_H = M([H.diff(x), H.diff(y)])
L_xyla = M([L.diff(x), L.diff(y), L.diff(la)])
L_xyla
L_xy = M([L.diff(x), L.diff(y)])
solxy = solve(L_xy)
solxy

sol = solve(L_xyla)
sol
grad_F.subs(sol)
grad_H.subs(sol)




#####
#
# 2019.2-C2-P1 (ambas as turmas)
# 2019oct29
#
#####

# «2019.2-C2-P1»  (to ".2019.2-C2-P1")
% (find-pdf-page "~/LATEX/2019-2-C2-P1.pdf")

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

# Questao 1
ss = sqrt(4*x + 5)
f = (2*x + 3) * ss
f.expand()

integrate(ss, x)
(2*x + 3).subs(x, (u-5)/4)
(2*x + 3).subs(x, (u-5)/4) * R(1,4)

F0 = a * ss ** 5 + b * ss ** 3
F0 = (a*x + b) * ss ** 3
(F0.diff(x) - f).expand().together()
(F0.diff(x) - f).expand().together() / ss
eq = (F0.diff(x) - f).expand().together() / ss
eq
so = solve(eq, [a, b])
so = solve(eq, [a, b, c])
so
F = F0.subs(so)
(F.diff() - f).expand()
F

U = 2*x + 3
v = sqrt(4*x + 5)
V = integrate(v, x)
u = U.diff(x)
F = U * v - integrate(u * V, x)
F
U * v
U * v - f
(F.diff(x) - f).expand()
(F.diff(x) - f).expand().together()



# Questao 2
f = x**3 * sqrt(1 - x**2)
f
F = integrate(f, x)
F

ss = sqrt(1 - x**2)
G = R(1,5) * ss**5 - R(1,3) * ss**3
G
(G.diff() - f).expand()

f = Sin(1)**3 * Cos(1)**2
expify(f)
fe = getsin(f, 5) + getsin(f, 3) + getsin(f, 1)
fe



# Questao 3
# (find-pdf-page "~/LATEX/2019-2-C2-P1.pdf")
f = Sin(5)**2 * Cos(6)**2
f
expify(f)
fe = getconst(f) + getcos(f, 2) + getcos(f, 10) + getcos(f, 12) + getcos(f, 22)
fe
integrate(fe, th)

# fe =
#
#   cos(2*th)   cos(10*th)   cos(12*th)   cos(22*th)   1
# - --------- - ---------- + ---------- - ---------- + -
#       8           4            4            8        4
# 
# integrate(fe, th) =
#
# th   sin(2*th)   sin(10*th)   sin(12*th)   sin(22*th)
# -- - --------- - ---------- + ---------- - ----------
# 4        16          40           48          176    





# (find-es "sympy" "tut-solve")

# Questao 4
# f0 = x**3 / (x**2 + 7*x + 12)
f0 = x**3 / (x**2 + 9*x + 20)
f0
f0.apart()
(f0.apart() - x + 9)
(f0.apart() - x + 9).together()
(f0.apart() - x + 9).together() + x - 9
f0.apart()
integrate(f0, x)



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

f = 3 + 4*Sin(5) + 6*Cos(7)
f
expify(f)
getconst(f)
getsin(f, 5)
getcos(f, 7)
getconst(f) + getsin(f, 5) + getcos(f, 7)




#####
#
# 2019.2-C2-P2
# 2019dec11
#
#####

# «2019.2-C2-P2» (to ".2019.2-C2-P2")
# (find-LATEX            "2019-2-C2-P2.tex")
# (find-pdf-page "~/LATEX/2019-2-C2-P2.pdf")

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

# Questao 1
f = Function('f')
eq = f(x).diff(x) - x**3 / exp(2*f(x))
eq 
sol = dsolve(eq)
sol
sol[1]
sol[1].rhs
g = sol[1].rhs
g.subs(x, 4)
solve(g.subs(x, 4) - 5)

# Questao 2
# (find-es "sympy" "linear-order2-real")
eq    = f(x).diff(x, x) - 8*f(x).diff(x) - 20*f(x)
eq
sol = dsolve(eq)
g = sol.rhs 
g
cond1 = g.subs(x, 0)         - 2
cond2 = g.diff(x).subs(x, 0) - 3
solg = solve((cond1, cond2))
solg
g.subs(solg)

# Questao 3
# (find-es "sympy" "linear-order2-complex")
eq    = f(x).diff(x, x) - 6*f(x).diff(x) + 25*f(x)
eq
sol = dsolve(eq)
sol
#
f1 = exp((3+4*I)*x)
f1
eq.subs(f(x), f1)
eq.subs(f(x), f1).expand()

# Questao 4
# (find-es "sympy" "exactify")
M0, N0 = 2 * x    * y**3, 3 * x**2 * y**2
M1, N1 = 2 * x**2 * y**3, 3 * x**3 * y**2
exactness(M0, N0)
exactness(M1, N1)
eq = (M0 * f(x).diff(x) + N0).subs(y, f(x))
eq
sol = dsolve(eq)
sol
mux = exactify_xie(M1, N1)
M2,N2 = mux*M1,mux*N1
M2,N2
exactness(M2,N2)





#####
#
# 2019.2-C2-VR
# 2019dec12
#
#####

# «2019.2-C2-VR» (to ".2019.2-C2-VR")

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

f = 1 / sqrt(4 + 9 * x**2)
f
F = integrate(f, x)
F

f = exp(sqrt(x)) / sqrt(x)
integrate(f, x)

f = exp(a*x) * cos(b*x)
f = exp(4*I*x) * cos(4*x)
integrate(f, x)





#####
#
# 2019.2-C2-VS
# 2019dec20
#
#####

# «2019.2-C2-VS»    (to ".2019.2-C2-VS")
# (find-LATEX            "2019-2-C3-VS.tex")
# (find-pdf-page "~/LATEX/2019-2-C3-VS.pdf")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
a,b,c,u  = symbols("a,b,c,u")

# Questao 2
f0 = x**2 / (x**2 + 3*x - 10)
f0
f0.apart()
(f0.apart() - 1)
(f0.apart() - 1).together()
(f0.apart() - 1).together() + 1
f0.apart()
integrate(f0, x)

# Questao 3
f = x**3 * sqrt(1 - x**2) ** 3
f
F = integrate(f, x)
F





#####
#
# 2020.1: slides sobre substituição trigonométrica
# 2020nov26
#
#####

# «2020.1-int-subst»  (to ".2020.1-int-subst")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
sx = sqrt(1 - x**2)
integrate(x*sx, x)
diff(sx, x)

f = x * sx
F = R(1,3) * (x**2 - 1) * sx
f
F
F.diff(x)
F.diff(x).together()
F.diff(x).together() - f



#####
#
# 2020.1-C2-MT1
# 2020dec10
#
#####

# «2020.1-C2-MT1»  (to ".2020.1-C2-MT1")

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
f = x - 1
F = integrate(f, x)
F
F.subs(x,2)
P = lambda b: (b, F.subs(x,b))
P(2)
P(2.1)
P(2.2)
P(2.3)
P(2.4)
P(2.5)
P(2.6)
P(2.7)
P(2.8)
P(2.9)
P(3)



#####
#
# 2020.1-C2-P1
# 2020dec01
#
#####

# «2020.1-C2-P1»  (to ".2020.1-C2-P1")

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

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questao 1
# (c2m201p1p 3 "questao-1")
# (c2m201p1    "questao-1")
f = x**2 - 1
f
integrate(f, (x, 0, 2))

# Questao 3
# (c2m201p1p 5 "questao-3")
# (c2m201p1    "questao-3")
f = x**3 / (x**2 + 5*x + 6)
apart(f)
fj1 = - x**3 / (x + 3)
fj2 =   x**3 / (x + 2)
together(fj1 + fj2)



#####
#
# 2020.1-C2-P2
# 2020dec02
#
#####

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

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")

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

f = 1 / (z * sqrt(z**2 - 1))
integrate(f, z)

f = 1 / (1 + 4 * x**2)
integrate(f, x)

# https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Derivatives_of_inverse_trigonometric_functions

asec(x).diff(x)
asec(x).diff(x) - 1 / (x * sqrt(x**2 - 1))
(asec(x).diff(x) - 1 / (x * sqrt(x**2 - 1))).together()
(asec(x).diff(x) - 1 / (x * sqrt(x**2 - 1))).subs(x, R(1,4))
(asec(x).diff(x) - 1 / (x * sqrt(x**2 - 1))).subs(x, R(3,4))



#####
#
# 2020.1-C3-P1
# 2020dec11
#
#####

# «2020.1-C3-P1»  (to ".2020.1-C3-P1")

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")

# Questao 1
# (c3m201p1p 3 "questao-1")
# (c3m201p1    "questao-1")

F = x*y
(x0,y0) = (4,2)
F.diff(x)
F.diff(y)
F.diff(x).subs(x,x0).subs(y,y0)
F.diff(y).subs(x,x0).subs(y,y0)


# Questao 2
# (c3m201p1p 4 "questao-2")
# (c3m201p1    "questao-2")

G = x**2 + 4 * y**2
H = sqrt(G)

# 2c (0.1 pts) e 2d (0.2 pts):
(M([diff(G, x), diff(G, y)]),
 M([diff(G, x), diff(G, y)]).subs(x, 3).subs(y, 1)
)
# 2e (0.3 pts) e 2f (0.4 pts):
(M([diff(H, x), diff(H, y)]),
 M([diff(H, x), diff(H, y)]).subs(x, 3).subs(y, 1)
)
 



#####
#
# 2020.1-C3-P2
# 2020dec11
#
#####

# «2020.1-C3-P2»  (to ".2020.1-C3-P2")



#####
#
# watts-strogatz
# 2020may30
#
#####

# «watts-strogatz» (to ".watts-strogatz")
# https://www.theatlantic.com/science/archive/2018/04/the-scientific-paper-is-obsolete/556676/
# http://worrydream.com/ScientificCommunicationAsSequentialArt/




#####
#
# bortolossi-5.5
# 2021mar04
#
#####

# «bortolossi-5.5»  (to ".bortolossi-5.5")
# (find-es "maxima" "bortolossi-5.5")
# (find-bortolossi5page (+ -162 177)   "[01] ...parciais de primeira ordem")

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)

* (eepitch-eshell)
* (eepitch-kill)
* (eepitch-eshell)
isympy3

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

ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
r,s,t,v,x,y,z = symbols("r,s,t,v,x,y,z")

# a)
f = sqrt(r**2 + s**2)
f.diff(r), f.diff(s)

# b)
f = t/s - s/t
f.diff(s), f.diff(t)

# c)
f = 2 * x**4 * y**3 - x * y**2 + 3 * y + 1
f.diff(x), f.diff(y)

# d)
f = ln(sqrt( (t+v)/(t-v) ))
f.diff(t), f.diff(v)
f.diff(t).together(), f.diff(v).together()

# (find-sh "which isympy3")


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
P = V2(x, sqrt(x))
P.subs(x, 4)


* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")

F = sin(exp(3*x))
F = sin(exp(2*x)) / 2
F.diff(x)



(+ 2.8 3.5 1.7)



* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
f = x**3
g = (x**2 + 3*x -10)
f / g
apart(f / g)

q = x - 3
f - q * g
r = (f - q * g).expand()
r
r / g



r

x**3 - 


* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
f = sqrt(25 - x**2)
f
f.diff(x)

ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
G = 25 - x**2 - y**2
F = G/5
F.diff(y)
F.diff(y).subs(x,1).subs(y,2)



f = sin(2*x + 3)
integrate(f, x)

f = 4 - (x - 2)**2
f
integrate(f, x)

f = exp(-x)
f = sqrt(x)

f = Function('f')
eq = f(x) + 1/f(x).diff(x)
eq
sol = dsolve(eq)
sol




* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
s = sqrt(x) 
s.diff()

f = (2*x + 3)**10
integrate(f, x)

f = (2*s + 3)**10 * s.diff()
integrate(f, x)

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
f = atan(x)
f.subs(x, 1)
f.diff(x)
f.diff(x).subs(x, 1)
f.diff(x).diff(x)
f.diff(x).diff(x).subs(x, 1)
f.diff(x).diff(x).diff(x).subs(x, 1)

F = sin(2 + sqrt(3*x + 4))
f = F.diff(x)
f
integrate(f, x)
latex(f)

u = 2 + sqrt(3*x + 4)
u.diff(x)
latex(u.diff(x))



* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
a,b = symbols("a,b")
f = a*x + b
f * f
integrate(f,   x)
integrate(f*f, x)
integrate(f,   (x, 0, 1))
integrate(f*f, (x, 0, 1))

A = integrate(f,   (x, 0, 1))
B = integrate(f*f, (x, 0, 1))
cond1 = A - 1
cond2 = B - 1
solve((cond1, cond2))

solve(A - 1)
solve(A - 1)
solve(B - 1)




#####
#
# Choosing the coefficients for a 3D perspective
# 2021aug09
#
#####

# «perspective»  (to ".perspective")
# (c3m202planotangp 27 "3D-fig")
# (c3m202planotanga    "3D-fig")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")

a,b,c,d,e,k = symbols("a,b,c,d,e,k")

a = 0.8
b = sqrt(1 - a**2)
d = k * c
e = sqrt(1 - c**2 - d**2)

pz = V3(0, a, b)
px = V3(c, d, e)
py = vprod(pz, px)

pz, px, py




#####
#
# 2021.1-C3-P1
# 2021sep03
#
#####

# «2021.1-C3-P1»  (to ".2021.1-C3-P1")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
z = y * (x-y)
z
# x0 = 0
x0 = -1
y0 = 1
z0 = z.subs(x, x0).subs(y, y0)
z0
ss = solve(z - z0, y)       # solutions
sa = solve(z - z0, y)[1]    # above
sb = solve(z - z0, y)[0]    # below
sa
sb
sa.subs(x, x0)
sa.diff(x)
sa.diff(x).subs(x, x0)

f = 2 + sqrt(x)
f.diff(x)




#####
#
# 2021.1-C2-P2
# 2021sep21
#
#####

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

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

# (c2m211p2p 13 "questoes-1def-gab")
# (c2m211p2a    "questoes-1def-gab")

# Daise:
C3 = symbols("C3")
f = sqrt(2 * (x**2/2 + C3))
f
f.diff(x)
f        .subs(C3, 0)
f.diff(x).subs(C3, 0)


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:               utf-8-unix
#  End: