Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
874 B
3
Indexable
Never
import numpy as np
def f(x,y):
    fx=x+y-1
    return fx
def Multi(f,x0,y0,h,xf):
    n = int((xf-x0)/h)+1
    x=np.zeros(n)
    y=np.zeros(n)
    x[0]=x0
    y[0]=y0
    yn0=[]
    print("xₙ","\t\t\t ","yₙ","\n",x[0],"\t\t\t ",y[0],sep="")
    #y
    for i in range(1, n-1):
        xi,yi = x[i-1],y[i-1]
        k1 = f(xi,yi)
        k2 = f(xi+h/2,yi+1/2*h*k1)
        k3 = f(xi+h/2,yi+1/2*k2*h)
        k4 = f(xi+h,yi+k3*h)
        x[i]=(round(xi+h,1))
        y[i]=((yi+(1/6)*h*(k1+2*k2+2*k3+k4)))
        print(round(x[i],2),"\t\t",round(y[i],4))
        #y'
    for i in range(0,n-1):
        yn0.append(f(x[i],y[i]))
    ya4=y[n-2]+(0.2/24)*(55*yn0[n-2]-59*yn0[n-3]+37*yn0[n-4]-9*yn0[n-5])
    yp4=f(xf,ya4)
    y4=y[n-2]+(0.2/24)*(9*yp4+19*yn0[n-2]-5*yn0[n-3]+yn0[n-4])
    print(round(xf,2),"\t\t",round(y4,4))
Multi(f,0,1,0.2,0.8)