Reference no: EM132662755
Numerical Integration
Question 1. Write C program to compute the integral I = a∫b f (x)dx where
f (x) = a0 + a1x + a2x2 + a3x3 + a4x4 + a5x5
and
a0 = 0.84885406
a1 = 31.51924706
a2 = -137.66731262
a3 = 240.55831238
a4 = -171.45245361
a5 = 41.95066071
with a = 0.0 and b = 1.5 using all the following approaches
(a) exact integration (when the integrand is a polynomial function, the integral can be exact).
(b) trapezoidal rule with the number of sub-intervals ni = {1, 2, 3, ...., 12}
(c) Simpson's one-third rule with the number of sub-intervals ni = {2, 4, 6, 8, 10, 12}
(d) Simpson's three-eights rule with the number of sub-intervals ni = {3, 6, 9, 12}
Please tabulate your results for (b), (c) and (d) and compare your results with the exact solution you obtained in (a). Show the order of accuracy of the methods used in (b), (c) and (d) by computing
order = log(∈i/∈i-1)/log(ni-1/ni) i = 0, 1, ....
where ∈i is the absolute error between the numerical integration and the exact solution. ni is the number of intervals. Note the above formula becomes calculable only when i ≥ 1.
(e) Gauss quadrature rule with the number of Gauss points ni = {1, 2, 3, 4}
R-K Time Integration
Question 2. Write a C program to solve
dy/dt = -y
using the Runge-Kutta method. Note that the analytical solution of this equation is y = e-t which can be used to compare with your numerical solution. To start the time integration, t0 = 0, y0 = 1.0 are given. Use your program to find the solution at tn = 6.0.
(a) RK-1.
(b) RK-2 (version 2).
(c) RK-3.
(d) RK-4 (version 1).
Requirements: for each method, please use the time step hi= {0.1, 0.05, 0.025, 0.0125, 0.00625} and compare your solution with the analytical solution. Calculate the order of accuracy of each method using the following formula and show it in the table.
order = log(∈i/∈i-1)/log(hi/hi-1)
where ∈ is the absolute error between numerical integration and the analytical solution.
h is the time step. Please tabulate your results as follows:
hi
|
RK-1
|
RK-2
|
RK-3
|
RK-4
|
|∈i|
|
order
|
|∈i|
|
order
|
|∈i|
|
order
|
|∈i|
|
order
|
0.1
|
|
-
|
|
-
|
|
-
|
|
-
|
0.05
|
|
|
|
|
|
|
|
|
0.025
|
|
|
|
|
|
|
|
|
0.0125
|
|
|
|
|
|
|
|
|
0.00625
|
|
|
|
|
|
|
|
|
Finite Difference Method
Question 3. Use the finite difference method to solve the following advection (wave equation) problem:
∂u/∂t + ∂u/∂x = 0, 0 ≤ x ≤ 1
u(x, 0) = 1, 0.25 ≤ x ≤ 0.75 , periodic b.c.
u(x, 0) = 0, otherwise , periodic b.c.
which is about a square wave propagated to the right at a constant speed of unity.
(a) Periodic b.c. means when the wave exits the right boundary it enters the left boundary.
(b) Note that this is an initial-value problem. You can use the explicit forward-time- backward-space (FTBS) scheme with appropriate time step determined by the stability condition
Δt ≤ Δx/a
where a is the wave speed (= 1 in this problem) and Δx = 1/40.
(c) plot u(x) vs. x at three time instants t = 0.0, t = 0.5, t = 1.0. Exact solution must also be plotted in the same figures for comparison purposes. Solid line is used for the exact solution and symbols for the numerical solution.
Question 4. Solve the following heat equation at t = 3.0.
∂T/∂t = α. ∂2T/∂x2 on 0 ≤ x ≤ L
T (x, 0) = 6 sin (πx/L), T (0, t) = 0, T (L, t) = 0
where α = 0.2 and L = π.
(a) The exact solution for this problem is given
T (x, t) = 6 sin (πx/L) e-α(π/L)2t
which can be used to compare with your numerical solution.
(b) Use a mesh with Δx = L/40.
(c) Use the explicit forward-time-central-space scheme to solve the equation. The following formulation is used to determine the stable time step.
Δt ≤ (Δx)2/2α
Plot T vs. x at t = 3.0. Solid line is used for the exact solution and symbols for the numerical solution.
(d) Use the implicit Crank-Nicholson scheme to solve the same problem. The time step can take 5 times the Δt in the previous explicit scheme (b). The Thomas algorithm (Google it online) can be used to solve the resulting tridiagonal system. Plot T vs. x at t = 3.0. Solid line is used for the exact solution and symbols for the numerical solution.