current position:Home>Who can help me see why this program reports errors

Who can help me see why this program reports errors

2022-02-02 20:13:59 CSDN Q & A

from sympy import *import mathdef f_fa1(alpha):    return math.sqrt(1 + alpha * alpha - alpha)def f_rho1(alpha):    return (2 * alpha - 1) / (2 - alpha)def f_beta1(alpha):    return 2 * f_fa1(alpha) / (2 - alpha)def f_epsilong2a(epsilong1a, alpha):    return epsilong1a * f_rho1(alpha)def f_epsilonga(epsilong1a, alpha):    return epsilong1a * f_beta1(alpha)def f_epsilong1b(epsilong1a, alpha2):    return epsilong1a * (2 - alpha2) / (2 * alpha - 1)def f_epsilong3b(epsilong1b, epsilong2a):    return 0 - epsilong1b - epsilong2adef f_epsilongb(epsilong1b, fa2, alpha2):    return epsilong1b * (2 * fa2) / (2 - alpha2)def f_epsilong3a(epsilong1a, epsilong2a):    return 0 - epsilong1a - epsilong2adef f(x, args1):    f = (args1[0] + args1[1]) ** args1[2] * (args1[3] * args1[4]) ** args1[5] / args1[6] - args1[7] * (                args1[8] + args1[9] * (2 * math.sqrt(1 + x * x - x)) / (2 - x)) ** args1[10] * (                    (2 * math.sqrt(1 + x * x - x)) / (2 * x - 1) * args1[11]) ** args1[12] / math.sqrt(1 + x * x - x) * (            math.e ** ((args1[13] + (-args1[14] * (2 - args1[15]) / (2 * args1[16] - 1) - args1[17])) - (args1[18] + args1[19])))    return f#  Newton's iteration def niu(args1):    x = symbols('x')    x0 = 0.01    x_list = [x0]    i = 0    while True:        if diff(f(x, args1), x).subs(x, x0) == 0:            print(' Extreme points :', x0)            break        else:            x0 = x0 - f(x0, args1) / diff(f(x, args1), x).subs(x, x0)            x_list.append(x0)        if len(x_list) > 1:            i += 1            error = abs((x_list[-1] - x_list[-2]) / x_list[-1])            if error == 0:                return x_list[-1]        else:            passif __name__ == '__main__':    f0 = 0.98    alpha = 0.3    epsilong1a = 0.005    epsilong3A = 0    epsilong3B = 0    epsilongA = 0    epsilongB = 0    n = -0.033    m = 0.172    epsilonga = f_epsilonga(epsilong1a, alpha)    beta1 = f_beta1(alpha)    fa1 = f_fa1(alpha)    epsilong2a = f_epsilong2a(epsilong1a, alpha)    epsilong3a = f_epsilong3a(epsilong1a, epsilong2a)    args1 = [epsilongA, epsilonga, n, beta1, epsilong1a, m, fa1, f0, epsilongB, epsilong1a, n, epsilong2a, m, epsilong3B,            epsilong2a, alpha, alpha, epsilong2a, epsilong3A, epsilong3a]    alpha2 = niu(args1)    fa2 = f_fa1(alpha2)    epsilong1b = f_epsilong1b(epsilong1a, alpha2)    epsilongb = f_epsilongb(epsilong1b, fa2, alpha2)    iter = 0    while epsilongb / epsilonga < 10:        iter += 1        epsilongA = epsilongA + epsilonga        epsilongB = epsilongB + epsilongb        epsilong3B = epsilong3B + f_epsilong3b(epsilong1b, epsilong2a)        epsilong3A = epsilong3A + epsilong3a        args1[0] = epsilongA        args1[8] = epsilongB        args1[13] = epsilong3B        args1[18] = epsilong3A        alpha2 = niu(args1)        fa2 = f_fa1(alpha2)        epsilong1b = f_epsilong1b(epsilong1a, alpha2)        epsilongb = f_epsilongb(epsilong1b, fa2, alpha2)    print("epsilong1a *  The number of iterations is :" + str(iter * epsilong1a))    print("epsilong2a *  The number of iterations is :" + str(iter * epsilong2a))



Refer to the answer 1:

First change the last two sentences to

print("epsilong1a *  The number of iterations is :" , (iter * epsilong1a))print("epsilong2a *  The number of iterations is :" , (iter * epsilong2a))

See if there's any hint




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022013576685.html

Random recommended