decimal.Overflow:[<;class';decimal.Overflow';>;]python中matplotlib中的错误

decimal.Overflow:[<;class';decimal.Overflow';>;]python中matplotlib中的错误,python,matplotlib,graph,Python,Matplotlib,Graph,我已经使用matplotlib在python中编写了一个简单的绘图,在这里我可以绘制到x=13,但我想将它绘制到x=20,在这种情况下,我得到一个错误,如下所示 错误 谢谢您的时间。对于RK,为什么要使用十进制?在使用十进制之前,它会在较小的“x”值上抛出相同的错误,使用它之后,x被允许直到13值,但当我输入20时,它会再次抛出相同的错误 Traceback (most recent call last): File "C:\Users\True Blue Operator\Deskt

我已经使用matplotlib在python中编写了一个简单的绘图,在这里我可以绘制到x=13,但我想将它绘制到x=20,在这种情况下,我得到一个错误,如下所示

错误
谢谢您的时间。

对于RK,为什么要使用十进制?在使用十进制之前,它会在较小的“x”值上抛出相同的错误,使用它之后,x被允许直到13值,但当我输入20时,它会再次抛出相同的错误
Traceback (most recent call last):
File "C:\Users\True Blue Operator\Desktop\12.py", line 41, in <module>
plt.plot(rk4(0,20,2,100,n)[0],rk4(0,20,2,100,n)[1],g[n])
File "C:\Users\True Blue Operator\Desktop\12.py", line 24, in rk4
k3[j]=h*(f(r+h/2, w[0]+k2[0]/2, w[1]+k2[1]/2,n)[j])
File "C:\Users\True Blue Operator\Desktop\12.py", line 10, in f
return z,-(2*x*z+(x**2)*(y**n))/(x**2)
decimal.Overflow: [<class 'decimal.Overflow'>]
import math
import decimal
decimal.getcontext().prec=100
k1=[0,0]
k2=[0,0]
k3=[0,0]
k4=[0,0]
def rk4(a,b,m,N,n):      #runge-kutta four metthod
    def f(x,y,z,n):      #system of differential equations
        return z,-(2*x*z+(x**2)*(y**n))/(x**2)
    h=decimal.Decimal((b-a)/N)
    r=decimal.Decimal(a)
    w=[1,0]             #boundary conditions
    c=[w[0]]            #list to append further w[0] for r>0  
    d=[0]               # list to append values of r
    print(n)
    for i in range (1,N+1):
        r=a+i*h         #iteration 
        for j in range (0,m):   #m is order of system
            k1[j]=h*(f(r, w[0], w[1],n)[j])
        for j in range (0,m):
            k2[j]=h*(f(r+h/2, w[0]+k1[0]/2, w[1]+k1[1]/2,n)[j])
        for j in range (0,m):
            k3[j]=h*(f(r+h/2, w[0]+k2[0]/2, w[1]+k2[1]/2,n)[j])
        for j in range (0,m):
            k4[j]=h*(f(r+h/2, w[0]+k3[0]/2, w[1]+k3[1]/2,n)[j])
        for j in range (0,m):
            w[j]=w[j]+(k1[j]+2*k2[j]+2*k3[j]+k4[j])/6
        c.append(w[0])
        d.append(r)
    return (d, c, w[1])
f=[]
e=[]
g=['.r-','.b-','.g-','.c-','.y-','.m-','.k-']
import numpy as np
import matplotlib.pyplot as plt
for n in range (0,7):
    print(n)
    plt.figure(1)   #create figure and axes
    plt.subplot(111)
    plt.plot(rk4(0,20,2,100,n)[0],rk4(0,20,2,100,n)[1],g[n]) #here the x=20 causes the error
    plt.xlabel('r')
    plt.ylabel('theta')
    axes = plt.gca()
    axes.set_xlim([0,13.5]) # set axes
    axes.set_ylim([-0.4,1])
    plt.plot([],[],g[n],label=n) # label plots
plt.plot([0,20],[0,0])
plt.legend()
plt.show() #show plots