import numpy as np
import sympy as sym
import matplotlib.pyplot as plt
from IPython.display import display, Math
# Parâmetros
a = 1
p = 1/(4*a)
h = 1
k = -2
n = 100
# Pontos do eixo-x para avaliarmos a função
x = np.linspace(h-2,h+2,n)
# Criando a função
y = a * (x - h)**2 + k
plt.figure(figsize=(10,7))
# Plotando a parabola
plt.plot(x,y, linewidth=2.5,label='Parabola')
# Plotando o vértice
plt.plot(h,k,'ro',markersize=8,label='Vértice')
# Plotando o ponto central
plt.plot(h,k+p,'go',label='Ponto central')
# Plotando a diretriz
d = k - p
plt.plot(x[[0,-1]],[d,d],label='Diretriz',linewidth=2.5)
plt.grid()
plt.legend(fontsize=14)
plt.show()
X,Y = np.meshgrid(range(0,10),range(0,15))
display(Math(sym.latex(sym.sympify(X))))
display(Math(sym.latex(sym.sympify(Y))))
plt.figure(figsize=(10,7))
plt.subplot(121)
plt.pcolormesh(X,edgecolor='k',linewidth=0.1)
plt.subplot(122)
plt.pcolormesh(Y,edgecolor='k',linewidth=0.1)
plt.axis('off')
plt.show()
x = np.linspace(-np.pi,2*np.pi,40)
y = np.linspace(0,4*np.pi,72)
X,Y = np.meshgrid(x,y)
Fxy = np.cos(X) + np.sin(Y)
plt.figure(figsize=(12,9))
plt.imshow(Fxy)
plt.axis('off')
plt.show()
# 2D Gaussian
x = np.linspace(-2,2,100)
X,Y = np.meshgrid(x,x)
s = 1
gauss2d = np.exp(-(X**2 + Y**2)/s)
plt.figure(figsize=(8,8))
plt.imshow(gauss2d)
plt.axis('off')
plt.show()
h = 3
k = -3
r = 7
axlim = r + np.max((abs(h),abs(k)))
x = np.linspace(-axlim,axlim,100)
X,Y = np.meshgrid(x,x)
Fxy = (X - h)**2 + (Y - k)**2 - r**2
plt.figure(figsize=(7,7))
plt.contour(X,Y,Fxy,0)
plt.plot([-axlim,axlim],[0,0],'k--')
plt.plot([0,0],[-axlim,axlim],'k--')
plt.plot(h,k,'ko',markersize=10)
plt.grid()
plt.show()
h = [-1.5,1.5]
x = np.linspace(-5,5,100)
X,Y = np.meshgrid(x,x)
plt.figure(figsize=(7,7))
for r in np.linspace(0.5,3,20):
for hi in h:
Fxy = (X - hi)**2 + Y**2 - r**2
plt.contour(X,Y,Fxy,0)
plt.grid()
plt.plot(h,[0,0],'k',linewidth=3)
plt.axis('off')
plt.show()
# Parâmetros
a = 1
b = 0.8
h = 2
k = 3
axlim = 2*np.max((a,b)) + np.max((abs(h),abs(k)))
x = np.linspace(-axlim,axlim,100)
X,Y = np.meshgrid(x,x)
# Criando a função
hyperbola = (X - h)**2/a**2 - (Y - k)**2/b**2 - 1
plt.figure(figsize=(10,7))
plt.grid()
plt.contour(X,Y,hyperbola,0)
plt.plot(h,k,'ro',markersize=10)
plt.plot([-axlim,axlim],[0,0],'k--')
plt.plot([0,0],[-axlim,axlim],'k--')
plt.show()
n = 30
ab = np.linspace(1,5,n)
axlim = 8
x = np.linspace(-axlim,axlim,100)
X,Y = np.meshgrid(x,x)
plt.figure(figsize=(7,7))
for i in range(n):
f1 = X**2/ab[i]**2 - Y**2/ab[i]**2 - 1
plt.contour(X,Y,f1,0,colors='k')
f2 = -X**2/ab[i]**2 + Y**2/ab[i]**2 - 1
plt.contour(X,Y,f2,0,colors='b')
plt.axis('off')
plt.show()