sample 3



        implicit none
        
        integer j,jmax
         
        parameter(jmax=1000)
        
        real x0,L0,xh,Lh,ah
        
        real x(0:jmax), L(0:jmax) ,a(0:jmax)

        real t(0:jmax), dt, tmax

        
c       初期条件
        write(0,*) 'initial condition: x,L ='
        
        read(*,*) x0,L0

        write(0,*) 'dt,tmax='

        read(*,*) dt,tmax

       
          
        x(0)=x0; L(0)=L0;
        
        t(0)=0.0

c       運動方程式を解く

        do j=0, jmax-1

           a(j)=-sin(x(j))           !運動方程式:a=-sin(x)
           
           xh=x(j)+L(j)*dt/2

           Lh=L(j)+L(j)*dt/2

           ah=-sin(xh)

           x(j+1)=x(j)+Lh*dt

           L(j+1)=L(j)+ah*dt

           t(j+1)=t(j)+dt

           if( t(j).gt.tmax) exit

        enddo   
        
c        結果を出力する

        do j=0,jmax-1
           
           write(*,*) t(j),x(j)


           if( t(j).gt.tmax) exit

        enddo



        stop

        end

[戻る]