I am a beginner to Python. I have written a function which calculates numbers that are of the order 10^-15.
While generating the output of the code, an error says "Numerical result out of range". What are possible reasons for which this error occurs?
Here is my code.
import numpy as np
import matplotlib.pyplot as plt
T=4.32*10**19
i=input("Number of iterations ")
h=T/i
a=[0.01]*6000
t=[0.0]*6000
data = np.loadtxt('/home/user/t.txt')
t=data[:]
def f (a):
if a!=0:
c=((0.75/a + 0.044/(a**2) + 0.74*(a**2))**0.5)
return c
else :
return 0
for n in range(0,5998):
k1=f ( a[n] );
k2=f ( a[n]+(h/2)*k1 );
k3=f ( a[n]+(h/2)*k2 );
k4=f ( a[n]+h*k3 );
a[n+1]=(a[n]+(h/6)*(k1 + 2*k2 + 2*k3 + k4))
fo=open("a_of_t.txt", "w")
for item in a:
fo.write("%e\n" % item)
fo.close()
plt.plot(t,a, 'k')
plt.show()
The error reads
line 23, in <module>
k3=f ( a[n]+(h/2)*k2 );
line 15, in f
c=((0.75/a + 0.044/(a**2) + 0.74*(a**2))**0.5)
OverflowError: (34, 'Numerical result out of range')