Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
898 B
1
Indexable
Never
def Nuton(x,u):
    u_old = (a+b)/2
    u_new = u_old
    k=0
    while((abs(H(x, u, u_new)))>eps):
        if(dH(x, u_new)==0):
            u_old = u_old +eps
        else:
            k += 1
            u_old = u_new
            u_new = u_old -H(x, u, u_old)/dH(x, u_old)

    return u_new

u = []
u.append(0)


#Неявный метод Эйлера
start = time.time()
for i in range(1,N):
    u.append(Nuton(x[i-1], u[i-1]))

Fun = []
for i in range(N):
    Fun.append(fi(x[i]))
plt.scatter(x, Fun,color='black')

end = time.time()
Eror = 0
#Вычисляем порядок точности для метода Эйлера
for i in range(N):
    e = abs(Fun[i] - u[i])
    if(Eror < e):
        Eror = e

plt.scatter(x, u,color='blue')
print("Количество узлов N =",N, "Ошибка Эйлер =",Eror,"time Эйлер",(end-start), "ms")
Leave a Comment