コード例 #1
0
ファイル: system01.py プロジェクト: drudox/ODEPyPackage
def main():

    start_time = datetime.now()

    # differential problem

    eq1 = lambda t, u: u[1]
    eq2 = lambda t, u: u[2]
    eq3 = lambda t, u: u[3]
    eq4 = lambda t, u: -8 * u[0] + np.sin(t) * u[1] - 3 * u[3] + t**2

    func1 = np.array([eq1, eq2, eq3, eq4])

    y0 = np.array([1., 2., 3., 4])
    system1 = rhs.Rhs(func1, 0, 4, y0, 100)

    fwdeuler = euler.Explicit(system1)
    fet, feu = fwdeuler.solve()

    bwdeuler = euler.Backward(system1)
    bet, beu = bwdeuler.solve()

    sieuler = euler.SemiImplicit(system1)
    siet, sieu = sieuler.solve()

    Impeuler = euler.Implicit(system1)
    iet, ieu = Impeuler.solve()

    leapfrog = multistep.LeapFrog(system1)
    lft, lfu = leapfrog.solve()

    #-----------------------------------------------------------------------------------------------------
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))
    #**{'color': 'paraview'}
    fig, axs = PalatinoItalic()(1, 1, figsize=(9.5, 4.5))
    #axs.plot(x,y,label='Analitycal', marker='o',linestyle='',markersize=4.5,color='C0',alpha=0.7)
    #axs.plot(fet,feu,label='Exp Euler')
    axs.plot(iet, ieu, label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')
    #axs.plot(bet,beu,label='NR-BWDEuler') #, linestyle=':')
    #axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 4th',linestyle=':')

    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(1.2)
    plt.setp(legend.get_texts(), color='#555555')
    axs.set(xlabel='time', ylabel='y(t)')
    axs.set_title(
        'dy$_1$/dt=y$_2$; dy$_2$/dt=y$_3$; dy$_3$/dt=y$_4$ ; dy$_4$/dt=-8y$_1$+sin(t)y$_2$-3y$_4$',
        y=1.05)
    plt.savefig('ODE/Results/system01.pdf')
    plt.show()
コード例 #2
0
ファイル: system05.py プロジェクト: drudox/ODEPyPackage
def main():

    start_time = datetime.now()

    # differential problem

    eq1 = lambda t, u: u[1]
    eq2 = lambda t, u: -1 / 2. * u[0] + 5 / 2. * u[1]

    func1 = np.array([eq1, eq2])

    y0 = np.array([6., -1.])
    system1 = rhs.Rhs(func1, 3, 5, y0, 50)

    fwdeuler = euler.Explicit(system1)
    fet, feu = fwdeuler.solve()

    bwdeuler = euler.Backward(system1)
    bet, beu = bwdeuler.solve()

    sieuler = euler.SemiImplicit(system1)
    siet, sieu = sieuler.solve()

    Impeuler = euler.Implicit(system1)
    iet, ieu = Impeuler.solve()

    leapfrog = multistep.LeapFrog(system1)
    lft, lfu = leapfrog.solve()

    #--------------------------------------------------------------------------------------------
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))
    #**{'color': 'paraview'}
    fig, axs = PalatinoItalic()(1, 1, figsize=(9.5, 4.5))
    #axs.plot(x,y,label='Analitycal', marker='o',linestyle='',markersize=4.5,color='C0',alpha=0.7)
    axs.plot(fet, feu, label='Exp Euler')
    axs.plot(iet, ieu, label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')
    #axs.plot(bet,beu[:,3],label='NR-BWDEuler') #, linestyle=':')
    #axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 4th',linestyle=':')

    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(1.2)
    plt.setp(legend.get_texts(), color='#555555')
    axs.set(xlabel='time', ylabel='y(t)')
    axs.set_title('2 y" - 5 y\' + y', y=1.05)
    plt.ylim(-300, 50)
    plt.savefig('ODE/Results/system05.pdf')
    plt.show()
コード例 #3
0
def main():

    start_time = datetime.now()

    ###---  differential problem  ---###
    eq1 = lambda t, u: u[1]
    eq2 = lambda t, u: u[2]
    eq3 = lambda t, u: 4 * u[0] - 3 * u[1] + 2 * u[2]

    func1 = np.array([eq1, eq2, eq3])

    y0 = np.array([0.1, 0.5, 0.1])
    system1 = rhs.Rhs(func1, 0, 2, y0, 100)

    fwdeuler = euler.Explicit(system1)
    fet, feu = fwdeuler.solve()

    bwdeuler = euler.Backward(system1)
    bet, beu = bwdeuler.solve()

    sieuler = euler.SemiImplicit(system1)
    siet, sieu = sieuler.solve()

    Impeuler = euler.Implicit(system1)
    iet, ieu = Impeuler.solve()

    leapfrog = multistep.LeapFrog(system1)
    lft, lfu = leapfrog.solve()
    #----------------------------------------------------------------------------------------------
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))

    fig, axs = PalatinoItalic()(1, 1, figsize=(9.5, 4.5))
    axs.plot(fet, feu, label='Exp Euler')
    axs.plot(iet, ieu, label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')
    #axs.plot(bet,beu[:,3],label='NR-BWDEuler') #, linestyle=':')
    #axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 4th',linestyle=':')

    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(1.2)
    plt.setp(legend.get_texts(), color='#555555')
    axs.set(xlabel='time', ylabel='y(t)')
    axs.set_title(
        'dy$_1$/dt = y$_2$  ;  dy$_2$/dt = y$_3$ ; dy$_3$/dt = 4y$_1$+3y$_2$+2y$_3$  ',
        y=1.05)
    plt.savefig('ODE/Results/system04.pdf')
    plt.show()
コード例 #4
0
def main():

    start_time = datetime.now()

    # differential problem
    eq1 = lambda t, u: (2 - 0.5 * u[1]) * u[0]
    eq2 = lambda t, u: (-1 + 0.5 * u[0]) * u[1]

    func1 = np.array([eq1, eq2])

    y0 = np.array([6., 2.])
    system1 = rhs.Rhs(func1, 0, 15, y0, 1200)

    fwdeuler = euler.Explicit(system1)
    fet, feu = fwdeuler.solve()

    bwdeuler = euler.Backward(system1)
    bet, beu = bwdeuler.solve()

    sieuler = euler.SemiImplicit(system1)
    siet, sieu = sieuler.solve()

    Impeuler = euler.Implicit(system1)
    iet, ieu = Impeuler.solve()

    midpoint = centdiff.MidPoint(system1)
    cdt, cdu = midpoint.solve()

    cdiff = centdiff.CentDiff2nd(system1)
    cd2t, cd2u = cdiff.solve()

    #    cranknicholson = rungekutta.CrankNicholson(problem1 , 'cn1.dat')
    #    cnt,cnu    = cranknicholson.solve()
    #
    #    am5 = adamsmethods.AdamsMoulton(problem1, 'AM5_1.dat')
    #    amt,amu = am5._5th.solve()
    leapfrog = multistep.LeapFrog(system1)
    lft, lfu = leapfrog.solve()

    rk3 = rungekutta.RK3(system1)
    rkt, rku = rk3.solve()
    #-----------------------------------------------------------------------------------------------------
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))
    #**{'color': 'paraview'}
    #fig,axs = Standard(**{'scheme':'vega'})(1,1,figsize=(8.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = StandardImproved(**{'scheme':'vega'} )(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = Elsevier()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = Elsevier(figsize=(9.5,4.5),**{'scheme':'mycolor'})(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexMathpazo(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexMathpazo(figsize=(9.5,4.5),**{'scheme':'mycolor'})(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexMathpazoBeamer(figsize=(6.5,4.5),**{'scheme':'mycolor'})(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexPaper()(1,1,figsize=(8.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = Helvet()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = HelvetBeamer()(1,1,figsize=(8.5,5.5))# ,**{'scheme':'nb'})
    #fig,axs = Beamer()(1,1,figsize=(8.5,5.5))# ,**{'scheme':'nb'})
    #fig,axs = Times()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = TimesItalicDefault(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TimesItalicImproved()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = TimesItalicModified()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})
    #fig,axs = SansModified(figsize=(9.5,4.5),**{'scheme':'vega'} )(1,1)
    #fig,axs = Fonts(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Palatino(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    fig, axs = PalatinoItalic(**{'scheme': 'gg'})(
        1, 1, figsize=(9.5, 4.5))  # ,**{'scheme':'nb'})

    #axs.plot(x,y,label='Analitycal', marker='o',linestyle='',markersize=4.5,color='C0',alpha=0.7)
    axs.plot(fet, feu, label='Exp Euler')  #,color='C0')
    #axs.plot(iet,ieu,label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')

    axs.plot(bet, beu, label='NR-BWDEuler')  #,color='C1') #, linestyle=':')
    #axs.plot(rkt,rku,label='RK3')
    #axs.plot(lft,lfu,label='Leap Frog') #, linestyle=':')
    #axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 3th')
    #axs.plot(cdt,cdu,label='Mid Point 2nd')
    axs.plot(cd2t, cd2u, label='CentDiff 2nd', linestyle='-')  #,color='C2')

    chartBox = axs.get_position()
    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(0.7)
    axs.set_position(
        [chartBox.x0, chartBox.y0, chartBox.width * 0.8, chartBox.height])
    plt.setp(legend.get_texts(), color='#2E3436')
    plt.legend(bbox_to_anchor=(1.03, 0.75), loc=2, borderaxespad=0.)

    axs.set(xlabel='time', ylabel='y(t)')
    axs.set_title(
        'dy$_1$/dt= (2 - 0.5y$_2$) y$_1$ ;  dy$_2$/dt = (-1 +0.5 y$_1$)y$_2$',
        y=1.05)

    plt.savefig('ODE/Results/system12.pdf')
    plt.show()
コード例 #5
0
ファイル: system02.py プロジェクト: drudox/ODEPyPackage
def main():

    start_time = datetime.now()
    a=4;
    c=1;
        
    # differential problem 
    eq1 = lambda t,u : a*(u[0]-u[0]*u[1]);
    eq2 = lambda t,u : -c*(u[1]-u[0]*u[1]);
        
    func1 = np.array([eq1,eq2])
    
    y0      = np.array([2.,1.])
    system1 = rhs.Rhs(func1, 0,10,y0,500 )

    fwdeuler = euler.Explicit(system1)
    fet,feu  = fwdeuler.solve()   

    bwdeuler = euler.Backward(system1)
    bet,beu  = bwdeuler.solve()
    
    sieuler = euler.SemiImplicit(system1)
    siet,sieu  = sieuler.solve()
    
    Impeuler = euler.Implicit(system1)
    iet,ieu  = Impeuler.solve()
    

    leapfrog    = multistep.LeapFrog(system1)
    lft,lfu   = leapfrog.solve()
        
    rk3 = rungekutta.RK3(system1)
    rkt,rku = rk3.solve()

    fig,axs = SansItalic()(1,1,figsize=(9.5,4.5))# ,**{'scheme':'nb'})


#----------------------------------------------------------------------------------------------   
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))
            #**{'color': 'paraview'}
    #fig,axs = Standard(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = StandardImproved(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Elsevier(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexMathpazo(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexMathpazoBeamer(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Beamer(figsize=(6.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TexPaper(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Helvet(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = HelvetBeamer(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Times(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TimesItalicDefault(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = TimesItalicImproved(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = PalatinoItalic(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})
    #fig,axs = Fonts(figsize=(9.5,4.5))(1,1)# ,**{'scheme':'nb'})

    axs.plot(fet,feu,label='Exp Euler')
    #axs.plot(iet,ieu,label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')
    axs.plot(bet,beu,label='NR-BWDEuler') #, linestyle=':')
    axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 3th',linestyle=':')

    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(1.2)
    plt.legend(loc='upper left')
    #axs.plot(x,y,label='Analitycal', marker='o',linestyle='',markersize=4.5,color='C0',alpha=0.7)
    plt.setp(legend.get_texts(), color='#555555')
    axs.set(xlabel = 'time' ,ylabel='y(t)')
    axs.set_title('dy$_1$/dt= -4 (y$_1$ - y$_1$y$_2$)  ;  dy$_2$/dt = -1(y$_2$ - y$_1$y$_2$)',y=1.05)
    plt.savefig('../Results/system02.pdf')   
    plt.show()
コード例 #6
0
def main():

    start_time = datetime.now()

    # differential problem
    m = 10
    k = 3
    g = 0.5
    eq1 = lambda t, u: u[1]
    eq2 = lambda t, u: -k / m * u[0] - g / m * u[1] + np.sin(t) / m

    func1 = np.array([eq1, eq2])

    y0 = np.array([0.1, 0.1])
    system1 = rhs.Rhs(func1, 0, 50, y0, 1000)

    fwdeuler = euler.Explicit(system1)
    fet, feu = fwdeuler.solve()

    bwdeuler = euler.Backward(system1)
    bet, beu = bwdeuler.solve()

    sieuler = euler.SemiImplicit(system1)
    siet, sieu = sieuler.solve()

    Impeuler = euler.Implicit(system1)
    iet, ieu = Impeuler.solve()

    leapfrog = multistep.LeapFrog(system1)
    lft, lfu = leapfrog.solve()

    #    cranknicholson = rungekutta.CrankNicholson(problem1 , 'cn1.dat')
    #    cnt,cnu    = cranknicholson.solve()
    #
    #    am5 = adamsmethods.AdamsMoulton(problem1, 'AM5_1.dat')
    #    amt,amu = am5._5th.solve()
    #
    #    rk4 = rungekutta.RK4(problem1,'RK4.dat')
    #    rkt,rku = rk4.solve()
    #----------------------------------------------------------------------------------------------
    end_time = datetime.now()
    print('Duration {}'.format(end_time - start_time))
    #**{'color': 'paraview'}
    fig, axs = PalatinoItalic()(1, 1, figsize=(9.5, 4.5))
    #axs.plot(x,y,label='Analitycal', marker='o',linestyle='',markersize=4.5,color='C0',alpha=0.7)
    axs.plot(fet, feu, label='Exp Euler')
    axs.plot(iet, ieu, label='Imp Euler')
    #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':')
    #axs.plot(bet,beu[:,3],label='NR-BWDEuler') #, linestyle=':')
    #axs.plot(lft,lfu,label='Leap Frog')
    #axs.plot(cnt,cnu,label='Crank Nicholson')
    #axs.plot(amt,amu,label='Adams Moulton 5th') #,linestyle=':')
    #axs.plot(rkt,rku,label='Runge Kutta 4th',linestyle=':')

    legend = leg = axs.legend()
    legend.get_frame().set_linewidth(1.2)
    plt.setp(legend.get_texts(), color='#555555')
    axs.set(xlabel='time', ylabel='y(t)')
    axs.set_title(
        'dy$_1$/dt = y$_2$  ;  dy$_2$/dt = -k/m y$_1$ -g/m y$_2$ + sin(t)/m  ',
        y=1.05)
    plt.savefig('ODE/Results/system03.pdf')
    plt.show()