Μαθηματικό μοντέλα μελέτης σε PC: Euler & Runge - Kutta

download Μαθηματικό μοντέλα μελέτης σε PC:  Euler & Runge - Kutta

of 5

Transcript of Μαθηματικό μοντέλα μελέτης σε PC: Euler & Runge - Kutta

  • 8/7/2019 PC: Euler & Runge - Kutta

    1/5

    1

    : : 2980: 24.11.2005

    PC:

    : EulerRunge - Kutta

  • 8/7/2019 PC: Euler & Runge - Kutta

    2/5

    2

    ::

    :

    xyy =

    i.

    ( ) ey =0 .

    ii. EulerRunge-Kutta /. ;

    //::

    Fortran, Euler Runge-Kutta., compilation , :

    Euler,

    Euler.out ( )yx, , Gnuplot ( )xfy = .

    Runge-Kutta, Runge-Kutta ( )yx, , Gnuplot ( )xfy = .

    ::

    Euler:

    ( )yxfy ,= nhxx

    on +=

    ( )nnnn yxhfyy ,1 +=+

    Runge-Kutta:

    ( )yxfy ,= nhxx on +=

    ( )nn yxhfk ,0 =

    ++=

    012

    ,2

    kh

    yh

    xhfknn

    ++=

    122

    ,2

    kh

    yh

    xhfknn

    ( )23 , kyhxhfk nn ++=

    ( )32101

    226

    1kkkkyy

    nn ++++=+

  • 8/7/2019 PC: Euler & Runge - Kutta

    3/5

  • 8/7/2019 PC: Euler & Runge - Kutta

    4/5

    4

    do i=-n,0write(*,2) x(i), y(i)write(1,2) x(i), y(i)

    2 format (2x,F5.2,2X,F8.3)enddo

    do i=1,nwrite(*,3) x(i), y(i)write(1,3) x(i), y(i)

    3 format (2x,F5.2,2x,F8.3)enddoend

    subroutine Runge_Kutta(h,n,x,y)implicit nonereal x(-1000:1000),y(-1000:1000),f,h,k1,k2,k3,k4

    integer i,ndo i=0,nk1=f(x(-i),y(-i))k2=f(x(-i)-h/2.,y(-i)+k1*h/2.)k3=f(x(-i)-h/2.,y(-i)+k2*h/2.)k4=f(x(-i)-h,y(-i)+k3*h)y(-i-1)=y(-i)-(k1+2*k2+2*k3+k4)*(h/6.)enddodo i=0,nk1=f(x(i),y(i))k2=f(x(i)+h/2.,y(i)+k1*h/2.)

    k3=f(x(i)+h/2.,y(i)+k2*h/2.)k4=f(x(i)+h,y(i)+k3*h)y(i+1)=y(i)+(k1+2*k2+2*k3+k4)*(h/6.)enddoopen (unit=4,file="expdata_Runge-Kutta.out")do i=-n,0write(4,5) x(i),y(i)write(*,5) x(i), y(i)

    5 format (2x,F5.2,2x,F8.3)enddodo i=1,n

    write(4,6) x(i), y(i)write(*,6) x(i), y(i)

    6 format (2x,F5.2,2x,F8.3)enddoend

    function f(u,z)implicit nonereal f,u,zf=u*zreturn

    end

  • 8/7/2019 PC: Euler & Runge - Kutta

    5/5

    5

    i

    ( )c

    x

    exycx

    y

    xdxydyxdx

    ydy

    xydxdyxydx

    dyxyy

    +

    =+=

    ==

    ===

    2

    22

    2ln

    0>y

    ( )c

    x

    exy+

    = 22

    ( ) ey =0

    ( )

    ( )1

    2

    2

    0

    2

    2

    10

    +

    +

    =

    ===

    x

    c

    exy

    ceey

    ii

    , , ( )xfy = Runge Kutta ( )xfy = Euler.