Professional Documents
Culture Documents
This coursework contributes to your degree and must be your own individual work. You
should not confer with others. You are also solely responsible for putting your own
coursework in the correct submission box by the date and time above. No marks will be given
if working is not shown.
The program can be used to solve, numerically, any initial-value problem of the form:
dY
= F, Y ( x0 ) = Y0
dx
In general, Y and F are vectors and F is a function of both x and Y.
Program Files
The following files can be downloaded from Blackboard or the web page for this module.
solve.f95 the Fortran source file
solve.in a sample input file
The basic procedures are already coded for you in subprograms SOLVE and STEP. For any
given equation the user should amend the code to specify:
derivative F in subroutine DERIV;
any required output in subroutine OUTPUT;
(optionally) the solution in function EXACT; this is only for testing purposes;
numerical parameters and initial values in file solve.in.
2 sample equations have been provided in the code (see subprograms DERIV and EXACT).
dy
(A) = x+ y , y ( 0) = 0 (solution: y = e x x 1 )
dx
d2 y dy
(B) 2
+ 3 + 2 y = 2x , y (0) = 1, y (0) = 1 (solution: y = 5e x 52 e 2 x + x 23 )
dx d x
In the latter case, the system has been reduced to first order with
dy
Y1 = y, Y2 =
dx
d Y1 Y2 Y1 1
= , = at x = 0
dx Y2 2 x 2Y1 3Y2 Y2 1
The default output (see subroutine OUTPUT) is both to screen and to a file (solve.out)
and consists of the following columns:
x y y(exact) error
Problem A: solved by the Euler method; step size 0.1; 10 steps; output every step.
1 number of dependent variables (NDEP)
EULER method of solution (METHOD)
10 number of steps (NSTEP)
0.1 step size (H)
1 output frequency (NPRINT)
0.0 initial x
0.0 0.0 initial Y(); number of values corresponds to NDEP
Problem B: solved by the Runge-Kutta method; step size 0.05; 20 steps; output every 2 steps.
2 number of dependent variables (NDEP)
RUNGE method of solution (METHOD)
20 number of steps (NSTEP)
0.05 step size (H)
2 output frequency (NPRINT)
0.0 initial x
1.0 1.0 initial Y(); number of values corresponds to NDEP
**** Very important **** The number of items of initial data for Y must correspond to the
number of dependent variables, NDEP.
For the first equation (problem A), run Euler ('EULER'), modified Euler ('MODIF') and
standard Runge-Kutta ('RUNGE') methods to derive the solution in 0 x 1 with step size
x = 0.1.
Compare all numerical solutions and the exact solution in a single table (using the same
precision as the output of the code) and on a single graph.
In your report:
include a table containing y values for all of these methods against x;
include the graph requested above;
state the maximum absolute error for each method;
comment briefly on the relative errors produced by the different methods;
state the advantages and disadvantages of using a high-order method like Runge-
Kutta compared with a low-order method like Euler.
Using the modified Euler method ('MODIF'), integrate problem A between x = 0 and x = 1
using step sizes x = 0.1, 0.05, 0.02, 0.01 in turn. (You will need to adjust NSTEP as the step
size changes, in order that xmax = 1.)
Tabulate E, log10 E and log10 x against x, where E is the absolute error at x = 1. Use the
same precision as the output of the code.
In your report:
include a table of absolute error (at x = 1) against stepsize;
include the graph;
state what is meant by an order-2 numerical scheme and determine whether
your graph is consistent with this.
u
x
is a parameter that is related to changes in the free stream: < 0 for decelerating flow, > 0
for accelerating flow and = 0 for constant free-stream velocity (zero pressure gradient).
Show how Equation (2) can be written as a first-order differential equation with vector
dependent variable.
In your report:
explain how this is done (e.g. by stating the components of the relevant vectors).
B2. Implementation
Modify subroutine DERIV to solve Equation (2). Modify subroutine OUTPUT to output f,
df/d and d2f/d2 but no exact solutions or errors (since these are unknown). Leave as a
variable to be modified when necessary.
In your report:
include the modified subroutines DERIV and OUTPUT.
1
For reference (i.e. you dont need to know this to do the question!), if the free-stream velocity U xm then
2 x , 2m
( x) = =
1+ m U 1+ m
and the case m = 0 gives the famous Blasius boundary-layer profile.
In each case employ a shooting method with a sequence of guesses for f (0) , so as to find
one which gives f (10) = 1.0 (10 is sufficiently close to in this problem!). The step size
and choice of integration method are entirely yours, but will need to be justified.
Note that, for non-zero , solutions can be very sensitive to f (0) ; you need only search in
the range (0, 2.0) here.
In your report:
plot a single graph (comparing the results for the three values of ) showing the
U
normalised velocity, = f () against for 0 5;
U
state the value of f (0) used for each value of ;
justify the choice of step size and integration method which you have used;
include the input file SOLVE.IN for any one of the three values of (but state
which!)
0 0 0 0 0 0 0
1 1
4 4 0 0 0 0 0
3 3 9
8 32 32 0 0 0 0
12
13
1932
2197 7200
2197
7296
2197 0 0 0
1 439
216 8 3680
513 4104
845
0 0
1
2 8
27 2 3544
2565
1859
4104 11
40 0
16
135 0 6656
12825
28561
56430 509 2
55
You are advised to check that both sample equations can be solved with these methods.
Use the Runge-Kutta-Fehlberg method and both explicit and implicit modified Euler methods
to solve the equation
dy
= x 5y3 , y(0) = 1
dx
using 10 steps of length x = 0.1. Compare your numerical solutions in a single table and on
a graph.
In your report:
include the modified subroutine STEP and, for the equation above, the modified
subroutine DERIV;
include the table and graph requested above.