ECE 759: Mathematics 1 Workshop 1
Due on September 30, 2015
Amodei 2:30
Contents
Gonzalo
|
Introduction |
3 |
||||||||||||||||||||||||||||||||||||||||||
|
Finite Difference Method Spatial Discretization |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
3 4 |
|
. Temporal Discretization |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
4 |
|
1 |
|||||||||||||||||||||||||||||||||||||||||||
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
|
Stability |
4 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Problem 1 |
5 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(1.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
6 |
|
(2.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
6 |
|
(3.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
6 |
|
Problem 2 |
7 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(1.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
7 |
|
(2.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
7 |
|
(3.) . |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
7 |
Page 2 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
Introduction
The first workshops of the subject Mathematics 1 focuses on the numerical solution of the one dimensional heat equation. The form of the heat equation is the following:
∂u ∂t = µ
∂ 2 u ∂x 2 + f (x, t)
(1)
Where u is the variable to solve, µ is the diffusion coefficient, f represents a source term, t is the time variable and x is the spatial coordinate. For a 1D finite line of length L, the heat equation must be combined with the following boundary and initial conditions
|
u(0, t) |
= |
u g (x, |
t) |
(2) |
|
u(L, t) |
= |
u d (x, |
t) |
(3) |
|
u(x, 0) = φ(x) |
(4) |
|||
|
(5) |
||||
The heat equation is a well known equation in partial derivatives and is capable of modeling numerous physical phenomena such as: heat transfer in stationary continuous mediums or specific laminar flows under certain conditions. The aim of this workshops is to solver this one dimensional heat equation using the finite difference method using different schemes for the temporal discretization and using a centered approach for the diffusive terms.
Finite Difference Method
The finite difference approximations for derivatives are one of the simplest and of the oldest methods to solve differential equations. It was already known by L. Euler (1707-1783) ca. 1768, in one dimension of space and was probably extended to dimension two by C. Runge (1856-1927) ca. 1908. The advent of finite difference techniques in numerical applications began in the early 1950s and their development was stimulated by the emergence of computers that offered a convenient framework for dealing with complex problems of science and technology. Theoretical results have been obtained during the last five decades regarding the accuracy, stability and convergence of the finite difference method for partial differential equations. The principle of finite difference methods is close to the numerical schemes used to solve ordinary dif- ferential equations (cf. Appendix C). It consists in approximating the differential operator by replacing the derivatives in the equation using differential quotients. The domain is partitioned in space and in time and approximations of the solution are computed at the space or time points. The error between the numerical solution and the exact solution is determined by the error that is commited by going from a differential operator to a difference operator. This error is called the discretization error or truncation error. The term truncation error reflects the fact that a finite part of a Taylor series is used in the approximation. Generally one can write an EDP in the following form:
∂u ∂t = F (u, x, t)
(6)
Where F is an spatial operator. For the example, for the heat equation F is from the form:
∂ 2 u F (u, x, t) = µ ∂x 2 + f (x, t)
(7)
For a fixed x j the general form of the EDP can be written as follow:
Page 3 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
du
dt = F (u, x j , t)
(8)
Spatial Discretization Temporal Discretization
The temporal derivative of the variable u is usually aproximated as:
∂u
u
n+1
j
− u
n
j
∂t ∼
∆t
Introducing this approximation in the equation 8 yields:
u
n+1
j
− u
n
j
And thus we can solve the equation for u
∆t
:
n+1
j
= F (u, x j , t)
u
n+1
j
− u
n
j
t
=
t
n
n+1
F (u, x j , t)dt
(9)
(10)
(11)
The different time schemes, modify the way the integral of the operator F (defined in 6) is defined. For the Euler explicit schemes, the integral is evaluated using data from the previous timestep F (u, x j , t) = F(u n , x j , t n )
(12)
without having to solve a linear system of equations, although
they have same stability limits. For the Euler implicit scheme, the integral is evaluated using the variable to be obtained F (u, x j , t) = F(u n+1 , x j , t n+1 )
u
n+1
j
− u
j
n+1
n
=
F(u n , x j , t n )∆t + o(∆t)
This explicit schemes allow to obtain u
j
(13)
The implicit schemes generally need of a bigger computational cost because they generate a linear system
. Usually, the implicit schemes present
u
n+1
j
− u
n
j
F(u n+1 , x j , t n+1 )∆t + o(∆t)
n+1
=
of equation which must be solve in order to obtain the variable u
j
more stability than the explicit schemes
Stability
|
In |
this section a study of the stability of the homogeneous one dimensional heat equation will be presented. |
|
A |
scheme is stable if roundoff errors are not amplified in the calculations. The Fourier method can be used |
|
to |
check if a scheme is stable, using the following approximation: |
(14)
The Von Neumann stability condition states that the following condition for the amplification factor G(w) must be fulfilled in order to ensure the stability of a discretized EDP:
n
u j
a n e iwj∆x
=
|G(w)| =
a
n+1
a
n
<= 1
(15)
Page 4 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
Introducing the Fourier approach (Equation 14) into the discretized equation and operating the expression yields:
|G(w)| = 1 + 2
µ∆t
∆x 2
(cos(w∆x) − 1) <= 1
(16)
Which gives a relation between the three parameters of the problem (∆t, ∆x and µ) in order to maintain the stability of the solution:
µ∆t ∆x 2 <=
1
2
(17)
And thus we can reach the Courant-Friedrichs-Lewy (CFL) condition for the heat equation using Euler explicit scheme and central differential scheme:
2µ∆t
CFL =
<= 1
(18)
∆x 2 In cause of using an Euler implicit scheme for the temporal integration, the amplification function is of the form:
|G(w)| =
|
|
1 |
|
|
|
1 + |
µ∆t |
(2 − cos(w∆x)) |
|
|
∆x 2 |
|||
<= 1
(19)
µ∆t
and there is no CFL condition, the
∆x 2 solution is stable for all the combinations of ∆t, ∆x and µ. Although, one must take into account that the
bigger the temporal and spatial increments are, the bigger the error in the solution.
This condition is fulfilled for every value of the parameter
Problem 1
Listing ?? shows a MATLAB script that was used to generate Figure ??.
Listing 1: MATLAB Function Used to Generate Figure ??
|
function homework_example |
||||||||||||||
|
%HOMEWORK_EXAMPLE Example |
MATLAB function for |
LaTeX homework templates. |
||||||||||||
|
% |
This |
function produces |
a |
figure |
by |
using |
a |
number |
of |
MATLAB commands. |
It |
|||
|
% |
should help |
generate |
the |
power |
of |
the \matlabscript macro for including |
||||||||
|
5 |
% |
MATLAB functions and |
scripts within code. |
|||||||||||
|
% |
||||||||||||||
|
% |
The |
figure |
generated |
by |
this function will |
be used |
to |
demonstrate how |
to |
|||||
|
% |
use |
\scalefig. |
||||||||||||
|
10 |
% |
Generate 100 |
random data |
points |
with a normal distribution |
|||||||||
|
X = randn(1, 100); |
||||||||||||||
|
% |
Generate a histogram |
in |
N |
at 100 |
centers specified |
at |
Xcenters |
|||||||
|
[N, Xcenters] |
= hist (X, |
length(X)/10); |
||||||||||||
|
15 |
||||||||||||||
|
% |
Plot |
the sample CDF of the data |
||||||||||||
|
clf ; |
||||||||||||||
|
subplot(211); |
||||||||||||||
Problem 1 continued on next
Page 5 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
Problem 1 (continued)
|
cdf_datafig |
= |
s t a ir s ( sort(X), linspace(0,1,length(X)) ); |
|||||||||||||||||
|
20 |
|||||||||||||||||||
|
% |
Plot |
an |
expected CDF |
on |
top |
of |
it |
||||||||||||
|
hold on; |
|||||||||||||||||||
|
xlims |
= |
xlim; linspace(xlims(1), xlims(2), 1000); |
|||||||||||||||||
|
expX = |
|||||||||||||||||||
|
25 |
cdf_expfig = |
plot( expX, normcdf(expX), ’r--’ ); |
|||||||||||||||||
|
% |
Label |
the |
figure |
||||||||||||||||
|
legend( [cdf_datafig, cdf_expfig], ’Data Distribution’, |
|||||||||||||||||||
|
’Expected Distribution’, |
4 |
); |
|||||||||||||||||
|
30 |
xlabel(’x’); ylabel(’F(x) = P(X \leq x)’); |
||||||||||||||||||
|
t |
i t l e (’Normal |
Cummulative |
Distribution |
Function’); |
|||||||||||||||
|
%%% Notice the use of |
TeX |
in |
the |
above |
ylabel. |
In MATLAB |
7.0, |
LaTeX |
can |
||||||||||
|
35 |
%%% also |
be |
used if the interpreter |
on |
the text |
object |
is |
changed from |
|||||||||||
|
%%% ’tex" |
to |
’latex’. |
|||||||||||||||||
|
% |
Plot |
the sample |
of |
the |
data |
||||||||||||||
|
subplot(212); |
|||||||||||||||||||
|
40 |
pdf_datafig |
= |
bar( Xcenters, N/length(X)/(Xcenters(2)-Xcenters(1)) ); |
||||||||||||||||
|
xlim( xlims ); |
|||||||||||||||||||
|
% |
Plot |
an |
expected |
on |
top |
of |
it |
||||||||||||
|
hold on; |
|||||||||||||||||||
|
45 |
pdf_expfig = |
plot( expX, normpdf(expX), ’r--’ ); |
|||||||||||||||||
|
% |
Label |
the |
figure |
||||||||||||||||
|
legend( [pdf_datafig, pdf_expfig], ’Data Density’, |
|||||||||||||||||||
|
’Expected Density’, |
1 |
); |
|||||||||||||||||
|
50 |
xlabel(’x’); |
||||||||||||||||||
|
ylabel(’dF(x)/dx’); |
|||||||||||||||||||
|
t |
i t l e (’Normal |
Probability |
Density |
Function’); |
|||||||||||||||
(1.)
Still no Latin.
(2.)
It can be demonstrated that the heat equation ( is of the form
u(x, t) = A 0 +
n=∞
n=1 A n cos(nπ/L)
+
B n sin( nπ
L
) e −µ(nπL) 2 t
(20)
And thus when t → ∞ the solution tends tou(x, t) = A 0
(3.)
As seen in the section and the equation , the explicit scheme used in this problem needs a value of CF L <= 1 in order to ensure the stability of the solution. Using a value of CF L = 1.1 makes the solution blow up in a few number of iterations.
Page 6 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
Problem 1
E
Problem 2
You were expecting lorem ipsum here, weren’t you?
(1.)
Still no Latin.
(2.)
It can be demonstrated that the heat equation ( is of the form
u(x, t) = A 0 +
n=∞
n=1
A n cos(nπ/L) + B n sin( nπ
L
) e −µ(nπL) 2 t
And thus when t → ∞ the solution tends to
(3.)
(21)
In this section, we will investigate the influence of the CFL number in the time discretization er- ror, and also the influence of the mesh spacing ∆x in the spatial discretization error, comparing our numerical solution u with the analytical solution u ex , using an Euler explicit temporal scheme combined with a second order central scheme for the diffusive terms. As previously stated we expect a temporal discretization error of order O(∆T ) and an spatial discretization error of order O(∆x 2 ). We will define the error for a given mesh as a function of the CFL number for a given time with the following expression:
E(t, CF L) =
i=0 max (u
i=t
n
j
−
u ex (x j , t n )) 2
κ
(22)
Where t is the time where the error is evaluated and κ is the number of iterations needed to reach up to time t with a given CFL. The figure represents the error previously defined as a function of the CFL number for a given time of t = 1, using logaritmic scale for both axes, as one might expect that the error is proportional to the CFL (or timestep) E = k ∗ CF L. As we can observe in the figure, the error obtained is practically proportional to the CFL, or in other words, the temporal discretization error is of order O(∆t). This result coincides with the theoretical value of the temporal discretization error.
10
10
10
CFL
Problem 2 [(3.)] continued on next
Page 7 of 8
Gonzalo
ECE 759 (Amodei 2:30): Mathematics 1
Problem 2
E
We will define the error for a given mesh as a function of the mesh spacing ∆ x for a given value of CF L = 0.1 with the following expression:
E(t, ∆x) =
i=t
i=0 max (u
n
j
−
u ex (x j , t n )) 2
κ
(23)
Where t is the time where the error is evaluated and κ is the number of iterations needed to reach up to time t with a given CFL. The figure represents the error previously defined as a function of the mesh spacing ∆x number for a given time of t = 1. In this case, the error obtained is practically proportional to the square of the mesh spacing , or in other words, the spatial discretization error is of order O(∆x 2 ). This result coincides with the theoretical value of the spatial discretization error.
Mesh Discretization Error
10
10
10
10
10
Page 8 of 8
Molto più che documenti.
Scopri tutto ciò che Scribd ha da offrire, inclusi libri e audiolibri dei maggiori editori.
Annulla in qualsiasi momento.