FORTRAN 90 - University of ? FORTRAN 90 Lecturer : Rafel Hekmat Hameed University of Babylon Subject : Fortran 90 College of Engineering

Download FORTRAN 90 - University of  ? FORTRAN 90 Lecturer : Rafel Hekmat Hameed University of Babylon Subject : Fortran 90 College of Engineering

Post on 16-Apr-2018

230 views

Category:

Documents

11 download

TRANSCRIPT

FORTRAN 90 LLeeccttuurreerr :: RRaaffeell HHeekkmmaatt HHaammeeeedd UUnniivveerrssiittyy ooff BBaabbyylloonn SSuubbjjeecctt :: FFoorrttrraann 9900 CCoolllleeggee ooff EEnnggiinneeeerriinngg YYeeaarr :: SSeeccoonndd BB..SScc.. MMeecchhaanniiccaall EEnnggiinneeeerriinngg DDeepp.. NNNuuummmeeerrriiicccaaalll SSSooollluuutttiiiooonnn ooofff FFFiiirrrsssttt OOOrrrdddeeerrr DDDiiiffffffeeerrreeennntttiiiaaalll EEEqqquuuaaatttiiiooonnn Euler Method The Euler methods are simple methods of solving first-order ODE, particularly suitable for quick programming because of their great simplicity, although their accuracy is not high. Consider: y' (x) = f(x, y) ; y (x0) = y0 (1) Let: xi = x0 + i h ; i = 0, 1,. , n yi = y (xi) true solution evaluated at points xi Yi the solution to be calculated numerically. Replace y'(x)=(Yi+1-Yi)/h Then Eq. (1) gets replaced with Yi+1 = Yi + h f(xi , Yi) EXAMPLE Find a numerical solution to some first-order differential equation with initial y(0) = 1, for 0 x 3. 5 dy/dx - y2 = -x2 dy/dx=1/5 (y2-x2) The initial data is y(0) = 1 , assume h=.5 . So x0 = 0 and y0 = 1. x1 = x0 + h = 0 +.5=.5, and y1= y0 + h f (x0, y0) = y0 +.1(y02 - x02) = 1 +.1(12 02)=1.1 x2 = x1 + h = .5 +.5=1 y2= y1 + h f (x1, y1) = 1.1+.1 (1.12 .52)=1.196 . . . i xi yi 0 0 1 1 .5 1.1000 2 1 1.1960 3 1.5 1.2390 4 2 1.1676 5 2.5 .9039 6 3 0.3606 program Euler_method implicit none real, dimension (20)::x,y integer::i real :: h,xo,yo,f read(*,*) xo,yo,h x(1)=xo y(1)=yo print*,"for x=",x(1) , "y=",y(1) i=2 do x(i)=x(1)+(i-1)*h y(i)=y(i-1)+h*f(x(i-1),y(i-1)) if (x(i).gt.3.0) exit print*,"for x=",x(i) , "y=",y(i i=i+1 enddo end real function f(x,y) implicit none real ::x,y f=1/5.0*(y**2-x**2 end

Recommended

View more >