Beispiel #1
0
def ingresar(f=None, a=None, b=None, toler=None, c_signif=None):
    """Función recursiva para ingresar los datos"""
    if f is not None:
        while True:
            answ = input(
                "¿Son correctos los datos?\n\nP(x) = {0} [{1}, {2}]\nc.s. = {3}, toler = {4}\n\n<Enter> Todo correcto\n2. Corregir\n(opción): "
                .format(f, a, b, c_signif, toler))
            if len(answ) == 0:  # caso base de la recursividad
                return f, a, b, toler, c_signif
            try:
                answ = int(answ)
            except ValueError:
                continue
            if answ == 2:
                break
    lect_func = lec_poly.LectorPolinomios()
    while True:
        f = lect_func.leer_polinomio()
        if f.grado >= 2:
            break
        else:
            print("¡ Ingrese un polinomio de grado >= 2 !")
    a, b = leer_intervalo(tag_min="a", tag_max="b")
    c_signif = leer_csignif()
    toler = calc_toler(c_signif)
    return ingresar(f, a, b, toler, c_signif)
def main(argv):
    c = leer_csignif()
    toler = calc_toler(c)
    n = leer_cuadrado()
    linea = Tangente(n)
    intervalo = calc_inter_confi(n, toler, linea)
    print_info(n, toler, linea, intervalo)
Beispiel #3
0
def main(argv):
    lector = LectorSEL(cuadrado=False, fracciones=False)
    c_signif = leer_csignif()
    tolerancia = calc_toler(c_signif)
    sel = lector.leer_sel()
    matriz = Matriz(sel.m_coef.renglones)
    b = Matriz(sel.m_indep.renglones)
    t_0 = []
    t_f = []
    t_proc_0 = []
    t_proc_f = []
    t_0.append(time.time())
    t_proc_0.append(time.process_time())
    v_incog = sel.gauss_jordan()
    t_proc_f.append(time.process_time())
    t_f.append(time.time())
    if not matriz.diag_dom:
        input("""
===============================================================================

A la matriz ingresada no se le pueden aplicar los métodos de Jacobi o Gauss-Seidel
================================================================================

Presione enter para continuar""")
    else:
        sel.m_coef = Matriz(matriz.renglones)
        sel.m_indep = Matriz(b.renglones)
        t_0.append(time.time())
        t_proc_0.append(time.process_time())
        sel.jacobi(tolerancia)
        t_proc_f.append(time.process_time())
        t_f.append(time.time())
    for i in v_incog:
        print(i)
def ingresar(f=None,
             a=None,
             b=None,
             toler=None,
             c_signif=None,
             M=None,
             delta_n=None):
    if f is not None:
        while True:
            answ = input(
                "¿Son correctos los datos?\n\nP(x) = {0} [{1}, {2}]\nM={3}\n\u0394N={4}\nc.s. = {5}, toler = {6}\n\n<Enter> Todo correcto\n2. Corregir\n(opción): "
                .format(f, a, b, M, delta_n, c_signif, toler))
            if len(answ) == 0:
                return f, a, b, toler, c_signif, M, delta_n
            try:
                answ = int(answ)
            except ValueError:
                continue
            if answ == 2:
                break
    lect_func = lec_poly.LectorPolinomios()
    while True:
        f = lect_func.leer_polinomio()
        if f.grado >= 2:
            break
        else:
            print("¡ Ingrese un polinomio de grado >= 2 !")
    a, b = leer_intervalo(tag_min="a", tag_max="b")
    M = leer_real("una cota superior", "M")
    delta_n = leer_entero("aumento de N", "\u0394N")
    c_signif = leer_csignif()
    toler = calc_toler(c_signif)
    return ingresar(f, a, b, toler, c_signif, M, delta_n)
def main(argv):
    c = leer_csignif()
    toler = calc_toler(c)
    x0, xf = leer_intervalo()
    print("intervalo real {} {}".format(x0, xf))
    pi_aprox, iteraciones, error = biseccion(x0, xf, toler)
    print_info(pi_aprox, toler, error, iteraciones)
Beispiel #6
0
def main(argv):
    coef, exp = leer_poly()
    coef_deriv, exp_deriv = derivar_poly(coef, exp)
    c_signif = leer_csignif()
    toler = calc_toler(c_signif)
    raices = set()
    for i in range(-50, 50, 4):
        try:
            r = newton_raphson(coef_deriv, exp_deriv, i, toler, c_signif)
            raices.add(r)
        except MaxIteraciones:
            continue
    if len(raices) > 0:
        print("\nSe encontraron extremos locales en: ")
        for i in raices:
            print("x = ", i)
    else:
        print("No se encontraron raices")
Beispiel #7
0
def main(argv):
    # coef, exp = leer_poly()
    # coef_deriv, exp_deriv = derivar_poly(coef, exp)
    c_signif = leer_csignif()
    x0 = 0.1
    xf = 4
    coef = []
    exp = []
    k = 0
    i = 1
    toler = calc_toler(c_signif)
    error = toler * 2
    raiz = None
    while error > toler:
        if k % 2 == 0:
            """terminos del polinomio de Maclaurin con k par tienen coeficiente cero por
            deriv_k_esima(sen) = +sen ó -sen"""

            k += 1
            continue
        coef.append(((-1)**i) / factorial(k))
        exp.append(k)
        try:
            raiz = falsa_posicion(coef, exp, x0, xf, c_signif)
        except Exception as ex:
            print(ex)
            raise
        if raiz is not None:
            error = ((pi - raiz) / pi) * 100
        if k > 10000:
            raise MaxIteraciones
        k += 1
        i += 1
    print("Se encontró\n pi = ", raiz)
    print("Con el polinomio de Maclaurin de {} terminos".format(k))
    print("De los cuales {} son No nulos".format(i - 1))
    print("")
    coef.reverse()
    exp.reverse()
    for i in range(len(coef)):
        print("{}x^{}".format(coef[i], exp[i]), end="  ")
    print("")