I would like to get the difference of two values, which are close to each other

Viewed 23

I have an equation, with parameter T. The equation has two terms, which's values are close to each other. By changing the value of T, the two terms get closer and closer to each other and I would like to get the difference of them, but the program gives zeros (instead of (for example) 3.125*10^-8). How can I fix this problem? The difference is supposed to be stored in the result array and the proper T values are supposed to be stored in the T array. Now, array T is:[2.5 3.75 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0] intead of [2.5 3.75 4.375 4.0625 3.90625...], and array result is: [0.463 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ] insead of [0.463 0.0313 -0.1383 -0.057 -0.0139 0.008449...].

T=np.zeros(10)
T[0]=2.5
h=2.5
h0=0.5
p = -math.pi
first=0
second = 0
k = -math.pi
L = 100000
d = (2 * math.pi) / L
K=2.5
result=np.zeros(10)
for i in range(len(result)-2):
    while k < math.pi:
        first = first + (math.tanh(math.sqrt((math.sin(k) ** 2) + (h - math.cos(k)) ** 2) / T[i]) * math.sqrt((math.sin(k))
            ** 2 + (h - math.cos(k)) ** 2))
        second = second + (
                       (L / (2 * math.pi)) * (((math.cos(k) - h0) * (math.cos(k) - h) + (math.sin(k) ** 2)) / (
                   math.sqrt((math.sin(k) ** 2) + (h0 - math.cos(k)) ** 2))) * (2 * math.pi) / L)
        k = k + d
    result[i]=(1 / L) * (first - second)
    if result[i] > 0:
        T[i+1] = T[i]+K/2
    if result[i] < 0:
        T[i+1] = T[i] -K/2
    K = K/2
    first = 0
    second = 0
print(result)
print(T)
0 Answers
Related