import diferencias_finitas_eliptica_homogenea_1D as df_h
import numpy as np
import matplotlib.pyplot as plt

def finite_difference_elliptic_1D(f, a, b, N):
    h = 1/N

    def fh(x):
        fx = f(x)
        fx[0] += a/h**2
        fx[-1] += b/h**2
        return fx

    x, u_num = df_h.finite_difference_elliptic_homogeneous_1D(fh, N)
    u_num[0] = a
    u_num[-1] = b

    return x, u_num

if __name__ == "__main__":
    f = lambda x: 4*np.pi**2*np.sin(2*np.pi*x)
    N = 100
    x_nh, u_nh = finite_difference_elliptic_1D(f, -1, 1, N)
    x_h, u_h = df_h.finite_difference_elliptic_homogeneous_1D(f, N)

    fig, (ax1, ax2) = plt.subplots(1, 2)

    ax1.plot(x_h, u_h)
    ax1.set_title("Solución al problema homogéneo")
    ax1.set_xlabel("x")
    ax1.set_ylabel("u")

    ax2.plot(x_nh, u_nh)
    ax2.set_title("Solución al problema no homogéneo")
    ax2.set_xlabel("x")
    ax2.set_ylabel("u")

    plt.show()
