Beispiel #1
0
def graficocont(f, a, b, grau):
    grau += 1
    g = []
    for i in range(grau):
        g.append(x**i)
    B = np.zeros((grau,grau))
    D = np.zeros((grau,1))
    for i in range(grau):
        for j in range(grau):
            B[i][j] = integrate(g[i]*g[j], (x, a, b))
        D[i][0] = integrate(g[i]*f, (x, a, b))

    Y = sistLinear(B, D, grau)

    P = 0
    for i in range(grau):
        P += Y[i][0]*x**i

    fig, ax = plt.subplots()
    z = np.arange(0,4,0.001)
    
    y = []
    for i in range(len(z)):
        y.append(P.subs(x,z[i]))

    b = np.arange(0,4,0.001)
    w = []
    for i in range(len(b)):
        w.append(f.subs(x,b[i]))

    ax.plot(b,w, label="Função f(x)")
    ax.plot(z,y, label='Função g(x)')
    ax.legend()
    ax.grid()
    plt.show()
Beispiel #2
0
def graficodis(pontos,grau):
    pts = len(pontos)
    g = np.zeros((grau+1,pts))
    f = []
    for j in range(pts):
        for i in range(grau+1):
            g[i][j] = pontos[j][0]**i
        f.append(pontos[j][1])

    B = np.zeros((grau+1,grau+1))
    for i in range(grau+1):
        for j in range(grau+1):
            soma = 0
            for k in range(pts):
                soma += g[i][k] * g[j][k]
            B[i][j] = soma

    D = []
    for i in range(grau+1):
        soma = 0
        for k in range(pts):
            soma += g[i][k] * f[k]
        D.append([soma])
    D = np.asarray(D)

    Y = sistLinear(B,D,grau+1)

    P = 0
    for i in range(grau+1):
        P += Y[i][0]*x**i

    fig, ax = plt.subplots()
    z = np.arange(-4,4,0.001)
    
    y = []
    for i in range(len(z)):
        y.append(P.subs(x,z[i]))

    b = []
    w = []
    for i in range(len(pontos)):
        b.append(pontos[i][0])
        w.append(pontos[i][1])

    ax.plot(b,w, "r*", markersize=6, label="Pontos da tabela")
    ax.plot(z,y, label='Função g(x)')
    ax.legend()
    ax.grid()
    plt.show()