ass2_solutions

# ass2_solutions - solutions Tue:04:11 2011 1 1 2...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: solutions.txt Tue Dec 06 13:04:11 2011 1 1: 2:******************************************* 3:./code/odemod.f90 4: 5:MODULE odemod 6:!**** 7:!**** Module file to hold various numerical methods for 8:!**** solving ordinary differential equations. 9:!**** 10: 11: IMPLICIT NONE 12: 13: 14: CONTAINS 15: 16: 17: !*********************************************** 18: 19: SUBROUTINE rk4(y,x,h) 20: !**** Does step of Runge-Kutta 4th Method **** 21: 22: ! *** Dummy declarations *** 23: REAL, INTENT(IN) :: h 24: REAL, INTENT(INOUT) :: y,x 25: 26: ! *** Local declarations *** 27: REAL :: k1,k2,k3,k4 28: 29: !**** Calculate k values **** 30: k1=h*ode(x,y) 31: k2=h*ode(x+h/2,y+k1/2) 32: k3=h*ode(x+h/2,y+k2/2) 33: k4=h*ode(x+h,y+k3) 34: 35: !**** Calculate y(x) **** 36: y=y+(k1+2*k2+2*k3+k4)/6 37: 38: x=x+h 39: 40: END SUBROUTINE rk4 41: 42: 43: !*********************************************** 44: 45: 46: SUBROUTINE adam2(y,x,h) 47: !******** Does one step of adams 2 step Method ******** 48: 49: ! *** Dummy declarations *** 50: REAL, INTENT(IN) :: h 51: REAL, INTENT(INOUT) :: y,x 52: 53: ! *** Local declarations *** 54: REAL :: y_in 55: INTEGER, SAVE :: count=1 56: REAL, SAVE :: oy1 !*** Store previous value 57: 58: 59: y_in=y !** Make a copy of incoming y_{n} 60: 61: If (count < 2) THEN !** If not enough starting values 62: CALL rk4(y,x,h) !** Do Runge-Kutta 4th order 63: count=count+1 !** Increment count 64: ELSE !** Do the adams 2 step method 65: y=y+h/2*(3*ode(x,y)-ode(x-h,oy1)) 66: x=x+h !** increment x 67: ENDIF solutions.txt Tue Dec 06 13:04:11 2011 2 68: 69: oy1=y_in !** Update y_{n-1} 70: 71: END SUBROUTINE adam2 72: 73: !*********************************************** 74: 75: SUBROUTINE adam3(y,x,h) 76: !******** Does one step of adams 3 step Method ******** 77: 78: ! *** Dummy declarations *** 79: REAL, INTENT(IN) :: h 80: REAL, INTENT(INOUT) :: y,x 81: 82: ! *** Local declarations *** 83: REAL :: y_in 84: INTEGER, SAVE :: count=1 85: REAL, SAVE :: oy1,oy2 !*** Store previous values 86: 87: y_in=y !** Make a copy of incoming y_{n} 88: 89: If (count < 3) THEN !** If not enough starting values 90: CALL rk4(y,x,h) !** Do Runge-Kutta 4th order 91: count=count+1 !** Increment count 92: ELSE !** Do the adams 3 step method!...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

ass2_solutions - solutions Tue:04:11 2011 1 1 2...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online