Sie sind auf Seite 1von 44

Mathematical Models - DN2266

Homework 4 - Numerical solution of PDEs


Teachers
Anna-Karin TORNBERG
Rikard OJALA
Authors
Pierre-Alexandre BEAUFORT
Hadrien VAN LIERDE
November 2013
Contents
1 Selected theoretical problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Divergence theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Orthogonality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Numerical solution of a dierential equation . . . . . . . . . . . . . . . . 2
1.4 Lax Friedrichs method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Unicity of solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 The convection diusion equation . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1 Order in space and time . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Stability condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Further study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 The wave equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Numerical solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Model of the ute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Direct computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4 Further study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
A Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
B DN2266_lab4_Q2cauchy.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
C DN2266_lab4_Q2cauchybis.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
D DN2266_lab4_Q2c.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
E DN2266_lab4_Q2cbis.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
F DN2266_lab4_Q3a.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
G DN2266_lab4_Q3b.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
0
1 Selected theoretical problems
1.1 Divergence theorem
If u(x, y) = x
2
in the square S = 1 < x, y < 1, then
u = 2[x, 0]
T
(u) = 2
The two members of the divergence equality are then
_ _
S
(u)dxdy =
_ _
S
2dxdy = 8
_
C
nuds =
_
C
u(dy x dx y)
=
_
1
1
2 x xdy +
_
1
1
2x x ( ydx) +
_
1
1
2 x xdy +
_
1
1
2x x ( ydx)
=
_
1
1
2 x xdy +
_
1
1
2 x xdy
= 2.2 + 2.2 = 8
We thus verify
_ _
S
(u)dxdy =
_ _
S
2dxdy =
_
C
nu ds
1.2 Orthogonality
In this subsection, we prove the following statement. If curlv = 0 and divw = 0 in a three-
dimensional volume V with w n = 0 on the boundary, then v and w are othogonal:
_ _ _
V
v
T
wdV = 0
To solve this problem, we will use the Poincar theorem
(i)
.
Theorem 1
Given a domain D simply connected and a vector eld F dened on D, if F is irrational on
D
F
i
x
j
=
F
j
x
i
, i, j
then F is conservative, i.e. there exists a scalar function dierentiable on D such that
F =
If we assume V is suciently smooth to be simply connected, there exists such that v =
on V . Then, we verify:
_ _ _
V
wdV =
_
V

x
i
w
i
dV
=
_ _
V
w
i
n
i

_ _ _
V

w
i
x
i
dV
= 0
(i)
KEUNIGS (R.),Mathmatiques 2, course given at the Universit catholique de Louvain.
1
One can actually show that any vector eld f can be split into v +w namely into a sum of an
irrotational component and a solenoidal component. The theorem that gives this representation
is known as Helmholtz decomposition or the fundamental theorem of vector calculus
(ii)
:
Theorem 2
Let F be a vector eld on a bounded domain V in R
3
, which is twice continuously dif-
ferentiable. Then F can be decomposed into a curl-free component and a divergence-free
component:
F = +A
where
(r) =
1
4
_
V

F(r

)
[r r

[
dV

1
4
_
S
F(r

) dS

[r r

[
A(r) =
1
4
_
V

F(r

)
[r r

[
dV

+
1
4
_
S
F(r

) dS

[r r

[
1.3 Numerical solution of a dierential equation
We consider a dierential equation of the form u

= f(u) = au. To solve this equation numeri-


cally, we consider the following scheme:
AU
n+1
+BU
n
+Cu
n1
= Df
n
+Ef
n1
(1)
If we consider a time step h, in order to have constants of the same dimension, we use the
constants

A = hA,

B = hB and

C = hC. The equation then becomes:

A
h
U
n+1
+

B
h
U
n
+

C
h
u
n1
= Df
n
+Ef
n1
We formulate the local truncation error as

n
=

A
h
u(x
n+1
) +

B
h
u(x
n
) +

C
h
u(x
n1
) Df(u(x
n
)) Ef(u(x
n1
))
For this method to be of order three, the local truncation error must be in O(h
3
). This means
that the constants have to satisfy the following equations:

A +

B +

C = 0

A

C D E = 0

A
2
+

C
2
+E = 0

A
3


C
3
E = 0
(2)
(ii)
Helmholtz Decomposition, http://en.wikipedia.org/wiki/Helmholtz_decomposition consulted on the
25/11/2013.
2
Or:
_

_
1 1 1 0 0
1 0 1 1 1
1
2
0
1
2
0 1
1
3
0
1
3
0 1
_

_
_

C
D
E
_

_
= 0
The matrix dening this system is of rank 4. This homogeneous system admits thus a non-zero
solution. The vector of solution (

A,

B,

C, D, E) must thus belong to the following subset of R
5
:
(
t
2
, 2t,
5
2
t, 2t, t), t R
And the vector of solution (A, B, C, D, E) must belong to the subset:
(
t
2h
,
2t
h
,
5t
2h
, 2t, t), t R
We note that according to these formula, all ve constants should be nonzero. For instance, if
we choose E = 1, we have:
(A, B, C, D, E) = (
1
2h
,
2
h
,
5
2h
, 2, 1) (3)
This method is consistent as the order of the local truncation error is greater than one, but we
can show that it is not stable. To that end, let us consider the second degree equation
Az
2
+Bz +C = 0
and show that this equation admits at least one z root with [z[ > 1. We note that the equation
above admits two solutions z
1
and z
2
in C such that z
1
z
2
=
C
A
thus [z
1
[ [z
2
[ = [
C
A
[. Here,
summing the third and fourth equation of the system (2), we obtain:
5A
6
+
C
6
= 0

C
A
= 5
[
C
A
[ = 5
We have [z
1
[ [z
2
[ = 5 > 1, thus at least one of the solution z z
1
, z
2
is such that [z[ > 1.
1.4 Lax Friedrichs method
Let us consider the equation u
t
= cu
x
and the Lax Friedrichs method given by:
u
n+1
j
=
u
n
j+1
+u
n
j1
2
at
u
n
j+1
u
n
j1
2x
To introduce the exact solution in the numerical scheme, we rst remind the following formulas
3
1. u(x
j
, t
n+1
) = u(x
j
, t
n
) + t
u
t
(x
j
, t
n
) +
t
2
2

2
u
t
2
(x
j
, t
n
) +C
1

3
t
2. u(x
j+1
, t
n
) = u(x
j
, t
n
) + x
u
x
(x
j
, t
n
) +
x
2
2

2
u
x
2
(x
j
, t
n
) +C
2

3
x
3. u(x
j1
, t
n
) = u(x
j
, t
n
) x
u
x
(x
j
, t
n
) +
x
2
2

2
u
x
2
(x
j
, t
n
) +C
3

3
x
for some constants C
1
, C
2
and C
3
. Placing these terms in the numerical scheme, we obtain
then:
u(x
j
, t
n
) + t
u
t
(x
j
, t
n
) +
t
2
2

2
u
t
2
(x
j
, t
n
) +C
1

3
t
= u(x
j
, t
n
) +
x
2
2
u
x
2
(x
j
, t
n
) +ct
u
x
(x
j
, t
n
)...
+
C
2
+C
3
2
x
3
+ctx
2
C
2
C
3
2
t
u
t
(x
j
, t
n
) +
t
2
2
c
2

2
u
x
2
(x
j
, t
n
) +C
1
t
3
=
x
2
2

2
u
x
2
(x
j
, t
n
) +ct
u
x
(x
j
, t
n
) +C
4
x
3
...
+C
5
tx
2
where C
4
=
C
2
+C
3
2
and C
5
= c
C
2
C
3
2
u
t
(x
j
, t
n
) c
u
x
(x
j
, t
n
) =

2
u
x
2
(x
j
, t
n
)
_
x
2
2t

t
2
c
2
_
C
1
t
2
+C
4
x
3
t
+C
5
x
2
Thus, the numerical dissipation is the coecient of u
xx
in the equation above:
x
2
2t

t
2
c
2
1.5 Unicity of solution
Let us consider the Poisson problem with Robin boundary conditions:
u = f x R
u
n
(x) +a(x)u(x) = 0 x
(4)
where a(x) > 0 on . The solution to this problem is unique.
Proof :
Let us assume there exists two solutions u and v C
2
() of problem 4. We dene w = u v. Then,
w satises:
w = 0 x R
w
n
(x) + a(x)w(x) = 0 x
(5)
we assume w is bounded on (if it was not, it would necessarily be unbounded on and the
Neumann boundary condition could not be veried). We have thus w C
2
(

), hence w, w and w
are square integrable. We can thus multiply the equation (5) by w and integrate the result over :
_

wwdx = 0
We transform this equality using Greens rst identity

[w[
2
dx +
_

ww ndx = 0
4
Using the boundary condition satised by w, we obtain:
_

[w[
2
dx +
_

aw
2
dx = 0
= |w|
2
L
2
()
+|

aw|
2
L
2
()
= 0
As the these two terms are positive, we must have
1. |w|
2
L
2
()
= 0 x , w(x) = C for a certain constant C R
2. |

aw|
2
L
2
()
= 0 |w|
2
L
2
()
= 0 x , w(x) = 0
Due to the two preceding observations, we verify w(x) = 0 x thus u = v.
5
2 The convection diusion equation
We consider the following convection-diusion equation:
u
t
+au
x
= u
xx
, for x '
u(x, t = 0) = f(x)
_
with the following nite dierence approximation:
u
n+1
j
u
n
j
t
+a
u
n
j+1
u
n
j1
2x
=
u
n
j1
2u
n
j
+u
n
j+1
(x)
2
(6)
where x > 0 is the step size and t > 0 is the time step, such that u
n
j
= u(x
j
; t
n
) =
u(jx; nt).
2.1 Order in space and time
We formulate the Taylor expansions of the terms appearing in the equation 6 (replacing the
approximate values by the exact values of the function).
1. u(x
j
, t
n+1
) = u(x
j
, t
n
) + t
u
t
(x
j
, t
n
) +
t
2
2

2
u
t
2
(
2
)
2. u(x
j+1
, t
n
) = u(x
j
, t
n
) + x
u
x
(x
j
, t
n
) +
x
2
2

2
u
x
2
(x
j
, t
n
) +
x
3
6

3
u
x
3
(x
j
, t
n
) +
x
4
24

4
u
x
4
(
2
)
3. u(x
j1
, t
n
) = u(x
j
, t
n
) x
u
x
(x
j
, t
n
) +
x
2
2

2
u
x
2
(x
j
, t
n
)
x
3
6

3
u
x
3
(x
j
, t
n
) +
x
4
24

4
u
x
4
(
3
)
where
1
,
2
and
3
[x
j
, x
j+1
] [t
n
, t
n+1
].
The local truncation error is given by

n
j
=
u(x
j
, t
n+1
) u(x
j
, t
n
)
t
+a
u(x
j+1
, t
n
) u(x
j1
, t
n
)
2x

u(x
j1
, t
n
) 2u(x
j
, t
n
) +u(x
j+1
, t
n
)
(x)
2
=
u
t
(x
j
, t
n
) +
t
2

2
u
t
2
(
2
) +a(
u
x
(x
j
, t
n
) +
x
2
6

3
u
x
3
(x
j
, t
n
) +a
x
3
48
(

4
u
x
4
(
2
)
x
4
24

4
u
x
4
(
3
))) . . .
(

2
u
x
2
(x
j
, t
n
) +
x
2
24
(

4
u
x
4
(
2
) +

4
u
x
4
(
3
)))
=
t
2

2
u
t
2
(
2
) +a(
x
2
6

3
u
x
3
(x
j
, t
n
) +a
x
3
48
(

4
u
x
4
(
2
)
x
4
24

4
u
x
4
(
3
))) (
x
2
24
(

4
u
x
4
(
2
) +

4
u
x
4
(
3
)))
= O(x
2
, t)
The method is thus of second order in space and rst order in time. This shows that the method
is consistent.
6
2.2 Stability condition
We use Fourier analysis to formulate a stability condition.
Let us consider a numerical solution of the type u
n
j
= u
n
()e
ix
j
for a certain parameter .
With this function, the terms appearing in (6) are
1. u
n+1
j
= u
n+1
()e
ix
j
2. u
n
j+1
= u
n
()e
ix
j
e
ix
3. u
n
j1
= u
n
()e
ix
j
e
ix
Using the results above, we calculate the following expressions
u
n
j+1
u
n
j1
= u
n
()e
ix
j
(e
ix
e
ix
)
= u
n
()e
ix
j
2i sin(x)
u
n
j+1
2u
n
j
+u
n
j1
= u
n
()e
ix
j
(e
ix
+e
ix
2)
= u
n
()e
ix
j
(e
ix
2
e

ix
2
)
2
= u
n
()e
ix
j
(2i sin(
ix
2
))
2
= u
n
()e
ix
j
(4 sin
2
(
x
2
))
According to (6), we have
u
n+1
j
= u
n
j
a
t
2x
(u
n
j+1
u
n
j1
) +
t
x
2
(u
n
j+1
2u
n
j
+u
n
j1
)
u
n+1
() = u
n
()
_
1 a
t
2x
(2i sin(x)) +
t
x
2
_
4 sin
2
_
x
2
___
= u
n
()

Q()
The result is stable if and only if for each frequency , we have [

Q()[ 1 +Ct. This means


we need
_
1 4
t
x
2
sin
2
_
x
2
__
2
+a
2
t
2
x
2
sin
2
(x) 1
Case 1: a = 0
If a = 0, then the condition above becomes
_
1 4
t
x
2
sin
2
_
x
2
__
2
In the worst case, we have
_
1 4
t
x
2
_
2
1
or
1
_
1 4
t
x
2
_
1
The right hand inequality is obviously always true. The left hand inequality gives the condition:
t
x
2

1
2
7
Case 2: = 0
If = 0, the stability condition is
1 +a
2
t
2
x
2
sin
2
(x) 1
which is never veried for a, x, t '
0
. The numerical scheme is thus almost
(iii)
never stable.
2.3 Further study
Let us come back to the intial problem:
u
t
+au
x
= u
xx
, < x <
with u(x, 0) = f(x). We will analyze the behavior of the solution for dierent values of . We
will focus on two dierent cases: the Cauchy problem - with Dirichlet boundary conditions -
and the case with 2 periodic initial data, f(x) = f(x+2) - for which the solution is periodic
in space.
Cauchy problem
We consider the following problem
u
t
+au
x
= u
xx
, < x <
u(x, 0) = f(x)
u(0, t) = u
i
u(10, t) = u
f
The problem is solved with numerical scheme described above with a discretization of M points
in space (x = 10/M), and a time step t (the MATLAB function solving this problem is in
appendix B). We rst analyze the problem with homogeneous boundary condition u
i
= u
f
= 0.
With large values of (typically, = 100, the solution is rather smooth as we can see on
gure 1. But when tends to zero, the solution appears to become less and less smooth (as
we can see on gures 2 and 3 respectively for = 1 and = 0.001). How can we explain
this phenomenon ? When tends to zero, the hyperbolic character of the equation becomes
more important (ultimately, when = 0, the equation is hyperbolic). But, in the case of a
hyperbolic equation, we can not specify both an inow and an outow boundary condition (re-
spectively in x = 0 and x = 10 as a is positive)
(iv)
. That is the reason why for tending to 0, the
numerical result is not smooth (in order to force the solution to satisfy the boundary condition).
(iii)
If x = k, k N, the method is stable.
(iv)
STRANG (G.), Introduction to Applied Mathematics, Wellesley-Cambridge Press, p. 555
8
0 2 4 6 8 10
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8 10
0
0.5
x 10
10
x
u
(
t
;
x
)
eta = 100 |Time = 1.999[s]
0 2 4 6 8 10
0
2
4
x 10
19
x
u
(
t
;
x
)
eta = 100 | Time = 3.999[s]
0 2 4 6 8 10
0
0.5
1
x 10
27
x
u
(
t
;
x
)
eta = 100 | Time = 6[s]
0 2 4 6 8 10
0
1
2
x 10
36
x
u
(
t
;
x
)
eta = 100 | Time = 8[s]
0 2 4 6 8 10
0
2
4
x 10
45
x
u
(
t
;
x
)
eta = 100 | Time = 10[s]
Figure 1: Numerical solution for = 100 with M = 20 space intervals, N = 10000 time
intervals between time 0 and time 10 and with homogeneous Dirichlet boundary conditions.
9
0 2 4 6 8 10
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8 10
0.5
0
0.5
x
u
(
t
;
x
)
eta = 1 |Time = 1.999[s]
0 2 4 6 8 10
0.2
0
0.2
x
u
(
t
;
x
)
eta = 1 | Time = 3.999[s]
0 2 4 6 8 10
0
0.05
0.1
x
u
(
t
;
x
)
eta = 1 | Time = 6[s]
0 2 4 6 8 10
0
0.05
0.1
x
u
(
t
;
x
)
eta = 1 | Time = 8[s]
0 2 4 6 8 10
0
0.02
0.04
x
u
(
t
;
x
)
eta = 1 | Time = 10[s]
Figure 2: Numerical solution for = 1 with M = 20 space intervals, N = 10000 time intervals
between time 0 and time 10 and with homogeneous Dirichlet boundary conditions.
10
0 5 10
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 5 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 |Time = 1.999[s]
0 5 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 3.999[s]
0 5 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 6[s]
0 5 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 8[s]
0 5 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 10[s]
Figure 3: Numerical solution for = 0.001 with M = 20 space intervals, N = 10000 time
intervals between time 0 and time 10 and with homogeneous Dirichlet boundary conditions.
However, we will observe dierent results if we solve the same problem with the following
numerical scheme:
u
n+1
j
u
n
j
t
+a
u
n
j
u
n
j1
2x
=
u
n
j1
2u
n
j
+u
n
j+1
x
2
still with homogeneous Dirichlet boundary conditions. The result for = 0.001 is plotted in
the gure 4 ((the MATLAB function solving this problem is in appendix C). Why is the result
smoother than with the other method? When the equation tends to be hyperbolic that is
tends to 0, the right hand term of the numerical scheme becomes negligible. If we neglect this
term, the numerical scheme becomes
u
n+1
j
u
n
j
t
+a
u
n
j
u
n
j1
2x
= 0
Thus, the value used to calculate the solution at time step n+1, are u
n
0
, ..., u
n
M1
. The informa-
tion at point of the outow boundary u
n
M
is thus not used. The solution is thus smooth except
for the last subinterval [x
M1
, x
M
]. Indeed, the boundary condition says u
n+1
M
= 0 whereas the
dierential equation and the numerical scheme also give a unique value for u
n
M
when initial and
inow boundary conditions are specied.
11
0 5 10
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 5 10
1
0
1
x
u
(
t
;
x
)
eta = 0.001 |Time = 1.999[s]
0 5 10
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 3.999[s]
0 5 10
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 6[s]
0 5 10
0.5
0
0.5
x
u
(
t
;
x
)
eta = 0.001 | Time = 8[s]
0 5 10
0.5
0
0.5
x
u
(
t
;
x
)
eta = 0.001 | Time = 10[s]
Figure 4: Numerical solution with the second numerical scheme for = 0.001 with M = 20
space intervals, N = 10000 time intervals between time 0 and time 10 and with homogeneous
Dirichlet boundary conditions.
For both numerical schemes, when is small, the system is overdetermined but, for the rst
numerical scheme, the error induced is spread over the entire interval. For the second numerical
scheme, the error induced is just observable in the subinterval [x
M1
, x
M
].
With other boundary conditions (varying with time for instance), the results obtained are
quite similar. For example, if we take the function sin(x)e
10t
to dene the boundary condition
(namely 0 at inow boundary and sin(10)e
10t
at outow boundary), the solution using the
rst numerical scheme with = 0 is given on gure 5.
12
0 2 4 6 8 10
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 |Time = 1.999[s]
0 2 4 6 8 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 3.999[s]
0 2 4 6 8 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 6[s]
0 2 4 6 8 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 8[s]
0 2 4 6 8 10
2
0
2
x
u
(
t
;
x
)
eta = 0.001 | Time = 10[s]
Figure 5: Numerical solution with the rst numerical scheme for = 0.001 with M = 20 space
intervals, N = 10000 time intervals between time 0 and time 10 and with time-varying Dirichlet
boundary conditions sin(x)e
10t
.
Periodic case
We now consider the following problem
u
t
+au
x
= u
xx
, < x <
u(x, 0) = f(x) with f a 2 periodic function
= u is a 2 periodic function
The problem is solved with numerical scheme described above with a descretization of M points
in space (x = 2/M), and a time step t (the MATLAB function solving this problem is in
appendix D). The results for = 1 and = 0.001 are shown on gure 6 and 7. Actually, one
can see that the result is smooth for any positive value of . That is because, when tends
to 0, ensuring that the solution is periodic only requires that the value at inow and outow
boundaries are equal but none of them is xed. In the preceding case, when was tending to
0, the system tended to be overdetermined but this is not the case any more.
13
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 1 |Time = 1.999[s]
0 2 4 6 8
0.02
0
0.02
x
u
(
t
;
x
)
eta = 1 | Time = 3.999[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 1 | Time = 6[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 1 | Time = 8[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 1 | Time = 10[s]
Figure 6: Numerical solution with the rst numerical scheme for = 1 with M = 20 space
intervals, N = 10000 time intervals between time 0 and time 10 and periodic solution.
14
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0.001 |Time = 1.999[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 3.999[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 6[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 8[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0.001 | Time = 10[s]
Figure 7: Numerical solution with the rst numerical scheme for = 0.001 with M = 20 space
intervals, N = 10000 time intervals between time 0 and time 10 and periodic solution.
15
With the second numerical method given in the preceding subsection, the result obtained is
very similar as we can show on gure 8 with = 0.001 ((the MATLAB function solving this
problem is in appendix E).
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
Time = 0 [s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0 |Time = 1.999[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0 | Time = 3.999[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0 | Time = 6[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0 | Time = 8[s]
0 2 4 6 8
1
0
1
x
u
(
t
;
x
)
eta = 0 | Time = 10[s]
Figure 8: Numerical solution with the second numerical scheme for = 0.001 with M = 20
space intervals, N = 10000 time intervals between time 0 and time 10 and periodic solution.
16
3 The wave equation
First, we solve a one-dimensional wave equation by using a numerical method. Then, we study
the physics of a ute owing to a wave equation. Moreover, we compute the eigenmodes in a
direct way. Finally, we analyze further the model of the ute.
3.1 Numerical solution
We consider the following wave equation in one dimension:

2
u
t
2
(t; x)

2
u
x
2
(t; x) = 0, x (0; 1)
u(t = 0; x) = u
0
(x)
u
t
(t = 0; x) = v
0
(x)
_

_
(7)
We are going to solve this equation with two homogeneous Dirichlet boundary conditions,
by using the Leap-Frog method. On ones hand, we impose homogeneous Dirichlet boundary
conditions, the wave described by the dierential problem is a standing wave and thus v
0
= 0.
On the other hand, the Leap-Frog method is a two-step method, we need one more initial
condition, given by the Alemberts formula
(v)
. Then, (7) becomes:
u
n+1
j
2u
n
j
+u
n1
j
=
2
(u
n
j+1
2u
n
j
+u
n
j1
), for 1 j N 1
with periodic boundary conditions:
u
n
0
= 0
u
n
N
= 0
with initial condition:
u
0
j
= u
0
(x
j
), for 0 j N
with supplementary initial condition:
u
1
j
=
1
2
[u
0
(x
j
t) +u
0
(x
j
+ t)], for 0 j N
_

_
(8)
where =
t
x
and u
n
j
= u(nt; jx), with x =
1
N
and x
j
= jx. Here, we use u
0
(x) =
exp(100(x
1
2
))
Owing to the initial conditions, the only unknown is u
n+1
j
, with 1 j N 1. We can thus
compute this by iteration, if we let u
n
= [u
n
j
]
1jN1
:
u
n+1
=
2
Au
n
+ 2u
n
u
n1
where A '
(N1)(N1)
: A =
_
_
_
_
_
_
_
_
_
_
2 1 0 0
1
.
.
.
.
.
.
.
.
.
.
.
.
0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
0 0 1 2
_
_
_
_
_
_
_
_
_
_
and n N.
DN2266_lab4_Q3a.m builds and computes such an iterative process (see appendix F). Figure 9
displays the solution of (8) for N = 64, = 1 and t [0; 2]. Actually, the initial pulse decreases
until it is divided into two pulses which go each one toward a dierent boundary. When a pulse
hits the boundary, it is reected, i.e. it comes back to its initial position but with an opposite
amplitude. Then the pulses merge into a single pulse which increases absolutely until its initial
amplitude. Then, it decreases absolutely again, is divided into two pulses and so on.
(v)
The Alemberts formula is the general solution for the wave equation: u(t; x) =
1
2
[g(x ct) + g(x + ct)] +
1
2c
_
x+ct
xct
h(y)dy is the solution of u
tt
= c
2
u
xx
s.t. u(t = 0) = g(x) and u
t
(t = 0) = h(x).
17
0.5 0 0.5 1 1.5
0.2
0.4
0.6
0.8
1
x
u
(
t
;
x
)
Time = 0 [s]
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
x
u
(
t
;
x
)
Time = 0.39062[s]
0 0.2 0.4 0.6 0.8 1
0.5
0.4
0.3
0.2
0.1
0
x
u
(
t
;
x
)
Time = 0.79688[s]
0 0.2 0.4 0.6 0.8 1
0.5
0.4
0.3
0.2
0.1
0
x
u
(
t
;
x
)
Time = 1.1875[s]
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
x
u
(
t
;
x
)
Time = 1.5938[s]
0.5 0 0.5 1 1.5
0
0.2
0.4
0.6
0.8
1
x
u
(
t
;
x
)
Time = 2[s]
Figure 9: Solution of (8), for N = 64, = 1 and t [0; 2]. The pulses hit the boundaries
around 0.4 [s] and 1.4 [s].
If we compute the solution for N = 1000 and = 1.0005
(vi)
, we get an unstable solution as
the CFL condition is not respected. The CFL condition is a necessary condition which states:
A stable numerical method computing the solution of an hyperbolic equation
(vii)
respects the
following expression:
[a[
t
x
1
We remind that the wave equation is an hyperbolic equation. Here, we have a = 1 and
t
x
= 1.0005, which implies that the CFL condition is not respected. Figure 10 displays the
unstable solution.
(vi)
Still for t [0; 2].
(vii)
u
t
= au
x
18
0.5 0 0.5 1 1.5
0.2
0.4
0.6
0.8
1
x
u
(
t
;
x
)
Time = 0 [s]
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
x
u
(
t
;
x
)
Time = 0.3992[s]
4 2 0 2 4
x 10
7
1.5
1
0.5
0
0.5
1
1.5
x 10
7
x
u
(
t
;
x
)
Time = 0.7994[s]
2 1 0 1 2
x 10
18
1
0.5
0
0.5
1
x 10
18
x
u
(
t
;
x
)
Time = 1.1996[s]
1.5 1 0.5 0 0.5 1 1.5
x 10
29
5
0
5
x 10
28
x
u
(
t
;
x
)
Time = 1.5998[s]
1.5 1 0.5 0 0.5 1 1.5
x 10
40
6
4
2
0
2
4
6
x 10
39
x
u
(
t
;
x
)
Time = 2[s]
Figure 10: Unstable solution of (8), for N = 1000 and = 1.0005. The solution is correct at
the beginning, for t (0; 0.4). However, as the numerical solution is unstable, the error due to
the discretization grows through the iterative process and the numerical solution explodes.
3.2 Model of the ute
We model the physics of a ute by the following dierential problem:
p

(; ) c
2
0
p

(; ) +D()p(; ) = G(, ), (0; L)


with Dirichlet boundary conditions:
p(; = 0) = 0
p(; = L) = 0
_

_
(9)
where:
p [Pa] is the mean dierence in pressure to the ambient pressure in a cross section of the
ute
[s] denotes the physical time
[m] denotes the distance from the mouth
c
0
[
m
s
] the speed of sound in air ; here c
0
= 340[
m
s
]
19
D() =
_

D() > 0 if belongs to a hole of the ute
0 otherwise
; unit: [s
2
]
G [
Pa
s
2
] denotes the blowing process into the mouth piece
L [m] denotes the total length of the ute
We begin by non-dimensionalizing (9). We let: u(t; x) := p
_
=
Lt
c
0
; = Lx
_
We compute:
d
dt
=
L
c
0
,
d
dx
= L, u
tt
= p

_
d
dt
_
2
and u
xx
= p

_
d
dx
_
2
= u
tt
(x; t) u
xx
(x; t) +
L
2
c
2
0
D(x)u(x; t) =
L
2
c
2
0
G(t; x)
Again, we let: d(x) :=
L
2
c
2
0
D(x) and g(x; t) :=
L
2
c
2
0
G(t; x) ; d: [/], g: [Pa].
Finally, (9) becomes:
u
tt
(t; x) u
xx
(t; x) +d(x)u(t; x) = g(t; x), x (0; 1)
with Dirichlet boundary conditions:
u(t; x = 0) = 0
u(t; x = 1) = 0
_

_
(10)
We are going to solve (10) by using the Leap-Frog method. We add two homogeneous initial
conditions, in order to initiate the Leap-Frog method. In fact, we assume that u(t 0; x) =
0.Then, (10) becomes:
u
n+1
j
2u
n
j
+u
n1
j
=
2
(u
n
j+1
2u
n
j
+u
n
j1
) + (t)
2
(g
n
j
d
j
u
n
j
),
for 1 j N 1
with periodic boundary conditions:
u
n
0
= 0
u
n
N
= 0
with initial conditions:
u
0
j
= 0, for 0 j N
u
-1
j
= 0, for 0 j N
_

_
(11)
where we use the same denitions than (8). Here we use g(t; x) = exp(10t) sin(x).
As in the point 3.1, we have only one unknown, which is u
n+1
j
, the other parameters are known.
Then, we can build an iterative process that is analog to this derived in 3.1:
u
n+1
=
2
Au
n
+ 2u
n
u
n1
+ (t)
2
(g
n
Du
n
)
where D '
(N1)(N1)
: D = diag(d
j
)
1jN1
. DN2266_lab4_Q3b computes such an iterative
process (see appendix G).
We are going to compute u(t; x) for several functions d(x). Remind that d(x) is zero where
there is no open hole and is a positive value where there is one. Once, the iterative computation
is done, we compute the Fourier transform for u(t; x = 0.25) in order to study the eigenmodes
of the ute of 33[cm]. We know that the fundamental eigenmode of a ute of length L is given
by:
f
0
=
c
0
2L
20
where c
0
= 344[
m
s
], the speed of sound in air. The fundamental eigenmode of the ute cor-
responds to the lowest frequency we can play with it. Actually, it is possible to play other
frequencies such that:

f =
c
0
2

(12)
where

(0; L). If there is such

f for a ute of length L, it means there is an open hole
centered in =

. Let us start our analysis:
d(x) = 0, x (0; 1).
It means that all the holes of the ute are closed. Figure 11 displays the Fourier transform
of u(t; x = 0.25). The only spike corresponds to the frequency

f = 521.2[Hz], which is
the frequency of the eigenmode.
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
10
1
X: 521.2
Y: 0.01084
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
No hole
Figure 11: Fourier transform of u(t; x = 0.25), where the frequency are rescaled for a ute of
33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. All the holes are closed.
d(x) = 1000s
_
1 + cos
_
2
xx
ref
w
_
, [
xx
ref
w
[ 0.5
0, otherwise
It describes the ute with only one open hole, which is centered in x = x
ref
. This hole
has a wide w and a size s. Here, we work with w = 0.05. Let us compute the eigenmodes
for dierent values of x
ref
and s:
x
ref
= 0.4969, s = 0.1
Figure 12 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 677.5[Hz], which is quite far from the one given by (12),

f = 1048.7[Hz]. Moreover, there is one other small spike corresponding to frequency


1616[Hz].
21
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 677.5
Y: 0.005857
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Hole in xref = 0.4969
s = 0.1
Figure 12: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. One open hole in x = 0.4969, i.e.
= 16.4[cm] for s = 0.1.
x
ref
= 0.4969, s = 1
Figure 13 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 990.2[Hz], which is close to this given by (12),

f = 1048.7[Hz].
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 990.2
Y: 0.00559
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Hole in xref = 0.4969
s = 1
Figure 13: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. One open hole in x = 0.4969, i.e.
= 16.4[cm] for s = 1.
x
ref
= 0.9393, s = 0.1
Figure 14 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 521.2[Hz], which is close to this given by (12),

f = 554.8[Hz].
Moreover, there are two other small spikes corresponding to 1042[Hz] and 1616[Hz].
22
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
10
1
X: 521.2
Y: 0.01042
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Hole in xref = 0.93939
s = 0.1
Figure 14: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. One open hole in x = 0.9393, i.e.
= 31[cm] for s = 0.1.
x
ref
= 0.9393, s = 1
Figure 15 displays the Fourier transform of u(t; x = 0.25). The rst spike is cor-
rupted by discretization. Actually, it should correspond to the frequencies

f
(521.2; 573.3)[Hz], which contains the frequency given by (12),

f = 554.8[Hz]. More-
over, there are two other small spikes corresponding to 1094[Hz] and 1668[Hz].
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 573.3
Y: 0.007125
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Hole in xref = 0.93939
s = 1
Figure 15: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. One open hole in x = 0.9393, i.e.
= 31[cm] for s = 1.
23
From these four cases, we observe that if we increase the size of the hole, the frequency
given by (12) gets closer to the corresponding frequency of an eigenmode. In fact, the
corresponding frequency increases with s. Actually, (12) yields that a the hole like a
shorter ute of length x
ref
. On the other hand, when x
ref
tends to 1, the corresponding
frequency is closer to this given by (12).
d(x) = s
1
d
h
(
xx
ref1
w
) +s
2
d
h
(
xx
ref2
w
), where d
h
(z) = 1000
_
1 + cos(2z), [z[ 0.5
0, otherwise
It describes the ute with two open holes, that are centered in x = x
ref1
and x = x
ref2
.
These holes have a width w and a size s
1
and s
2
, respectively. Here, we work with
w = 0.05. Let us compute the eigenmodes for dierent values of x
ref12
and s
12
:
x
ref1
= 0.4969, x
ref2
= 0.9393, s
1
= 1, s
2
= 1
Figure 16 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 990.2[Hz], which is the same than the one we obtain in the
case of a single hole in x
ref
= 0.4969, for a size s = 1 (see gure 13).
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
4
10
3
10
2
X: 990.2
Y: 0.005622
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Holes in xref1 = 0.49697, xref2 = 0.93939
s1 = 1, s2 = 1
Figure 16: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. Two open holes in x = 0.4969
and x = 0.9393, i.e. = 16.4[cm] and = 31[cm] for s
1
= s
2
= 1.
x
ref1
= 0.4969, x
ref2
= 0.9393, s
1
= 0.1, s
2
= 1
Figure 17 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 729.6[Hz], which is dierent from what we obtain in the case
of a single hole in x
ref
= 0.4969, for a size s
1
= 0.1 (see gure 12). Moreover, there
are two other spikes corresponding to 1094[Hz] and 1720[Hz].
24
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 729.6
Y: 0.00907
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Holes in xref1 = 0.49697, xref2 = 0.93939
s1 = 0.1, s2 = 1
Figure 17: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. Two open holes in x = 0.4969
and x = 0.9393, i.e. = 16.4[cm] and = 31[cm] for s
1
= 0.1 and s
2
= 1.
x
ref1
= 0.2, x
ref2
= 0.9393, s
1
= 0.1, s
2
= 1
Figure 18 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
to the frequency

f = 625.4[Hz], which is not the same we get in the case of a single
hole in x
ref
= 0.9393, for a size s = 1, i.e. (521.2; 573.3)[Hz] (see gure 15).
Observe that x
ref1
< 0.25. Moreover, there are two other small spikes corresponding
to frequencies 1199[Hz] and 1720[Hz].
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 625.4
Y: 0.006358
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Holes in xref1 = 0.2, xref2 = 0.93939
s1 = 0.1, s2 = 1
Figure 18: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. Two open holes in x = 0.2 and
x = 0.9393, i.e. = 6.6[cm] and = 31[cm] for s
1
= 0.1 and s
2
= 1.
x
ref1
= 0.1, x
ref2
= 0.9393, s
1
= 0.1, s
2
= 1
Figure 19 displays the Fourier transform of u(t; x = 0.25). The rst spike corresponds
25
to the frequency

f = 573.3[Hz], which is not exactly the same we get in the case
of a single hole in x
ref
= 0.9393, for a size s = 1, i.e. (521.2; 573.3)[Hz] (see gure
15).Observe that x
ref1
< 0.25. Moreover, there are two other spikes corresponding
to 1147[Hz] and 1668[Hz].
0 200 400 600 800 1000 1200 1400 1600 1800 2000
10
5
10
4
10
3
10
2
X: 573.3
Y: 0.009679
Frequency [Hz]
|
U
|
Norm Fourier transform of U(t,x=.25)
frequency is rescaled for a flute of 33[cm]
Holes in xref1 = 0.1, xref2 = 0.93939
s1 = 0.1, s2 = 1
Figure 19: Norm of the Fourier transform of u(t; x = 0.25), where the frequency are rescaled
for a ute of 33[cm], such that f
33cm
= f
adimensionless

c
0
0.33[m]
. Two open holes in x = 0.1 and
x = 0.9393, i.e. = 3.3[cm] and = 31[cm] for s
1
= 0.1, s
2
= 1.
From the four last cases, we notice that the presence of another open hole alters the
behavior of the eigenmode, except for the case x
ref1
= 0.4969 and x
ref2
= 0.9393 with
s
1
= s
2
= 1. Generally, there are two other spikes, which are higher than these we could
observe for one single open hole.
3.3 Direct computation
Actually, we can compute the basic frequency of a system in a direct way. We know that a
standing wave U(t; x) with frequency f and amplitude v(x) has the following expression:
U(t; x) = v(x) exp(i2ft) (13)
We replace u(t; x) by the expression of U(t; x) in (10) and we use U
tt
= (2f)
2
U in order to
get:
v
xx
+dv = (2f)
2
v (14)
We observe that (2f)
2
is an eigenvalue and v(x) an eigenfunction of the operator
xx
+d(x).
Observe that v(x) is the solution of (14)
We are going to use the approximation of this operator given by the discretization of the
dierential problem:

xx
+d(x) = A +D
(vii)
here, x = 0.25
26
where A and D are the matrix of the iterative process solving (11).
We compute thus the basic frequency by using the following expression
f =

0
2
(15)
Let us compare the obtained frequencies with the Fourier transform and with the direct com-
putation:
No open hole
Fourier Direct
521.2[Hz] 521.19[Hz]
One open hole
x
ref
s Fourier Direct
0.4969 0.1 677.5[Hz] 702[Hz]
0.4969 1 990.2[Hz] 983.9[Hz]
0.9393 0.1 521.2[Hz] 528.9[Hz]
0.9393 1 (521.2; 573.3)[Hz] 548.6[Hz]
Two open holes
x
ref1
s
1
x
ref2
s
2
Fourier Direct
0.49697 1 0.9393 1 990.2[Hz] 1010.7[Hz]
0.49697 0.1 0.9393 1 729.6[Hz] 730.8[Hz]
0.2 0.1 0.9393 1 625.4[Hz] 610.8[Hz]
0.1 0.1 0.9393 1 573.3[Hz] 568.6[Hz]
We can conclude that the frequency computed by (15) agree with the spikes in the frequency
domain.
Figures 20, 21 and 22 display the dierent v(x) corresponding to the frequencies that are
returned by the direct computation. We observe that the eigen functions have a kind of node
where there is a hole. Besides, the value in the node tend to be zero for larger sizes of hole.
Remind that the eigen functions are solutions of (14)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
x
v
(
x
)
Eigen function
No hole
Figure 20: Eigen function for the case without open hole.
27
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.12
0.1
0.08
0.06
0.04
0.02
0
x
v
(
x
)
Eigen function
Single hole in xref = 0.4969
Size s = 0.1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
x
v
(
x
)
Eigen function
Single hole in xref = 0.4969
Size s = 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
x
v
(
x
)
Eigen function
Single hole in xref = 0.9393
Size s = 0.1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
x
v
(
x
)
Eigen function
Single hole in xref = 0.9393
Size s = 1
Figure 21: Eigen functions for cases with one open hole.
28
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
x
v
(
x
)
Eigen function
Two holes in xref1 = 0.4969 and xref2 = 0.93939
s1 = 1and s2 = 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
x
v
(
x
)
Eigen function
Two holes in xref1 = 0.4969 and xref2 = 0.93939
s1 = 0.1and s2 = 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
x
v
(
x
)
Eigen function
Two holes in xref1 = 0.2 and xref2 = 0.93939
s1 = 0.1and s2 = 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
x
v
(
x
)
Eigen function
Two holes in xref1 = 0.1 and xref2 = 0.93939
s1 = 0.1and s2 = 1
Figure 22: Eigen functions for cases with two open holes.
29
3.4 Further study
Let us imagine we want to model a ute with 7 holes such that it is possible to play these
frequencies:
f
0
= 523.15[Hz]
f
k
= 2
k
12
f
0
, k N
0
by combinations of open and close holes.
We use then:
d(x) =
7

i=1
s
i
d
h
(
x x
ref
i
w
i
)
where:
d
h
= 1000
_
1 + cos(2z), [z[ 0.5
0, otherwise
x
ref
i
is the center, w
i
is the width and s
i
the size of the i-th hole.
In order to model such a ute, we could proceed by trial and error, but there are too many
possibilities and it is quite hard to correct the values of the parameters with a feedback process.
An other way to proceed could be using the direct computation:
Av +Dv = (2f)
2
v
built from the discretization of the operator
xx
+d.
We should determine the entries of the matrix D
(viii)
and of the eigen vector
(ix)
v from the
frequency f and the matrix A. For this, we derive an optimization problem (that gives an
approximate solution, optimal in some sense):
min
D;v=0
|Dv Av (2f)
2
v|
2
where A, f are given and, | | is a matrix norm.
Once the matrix D is determined, we could compute the parameters by solving a system that
is formed by nding the solution of
min
s
i
,w
i
,x
ref
i
|D diag(d(x
i
))|
where | | is a functional norm.
(viii)
D = diag(d(x
i
))
(ix)
Which contains the value of v(x
i
) in the i-th entry.
30
A Appendix
B DN2266_lab4_Q2cauchy.m
1 %%
2 %DN2266_lab4_Q2cauchy(M,N,xi,xf,T,eta ,u0,ui ,uf) solves the differential
3 %problem
4 %u_t + a*u_x = eta*u_xx
5 %with Dirichlet boundary conditions u(xi)=ui, u(xf)=uf
6 %by using central scheme for the space derivatives and unilateral for the
7 %time.
8 %@PRE:
9 %- M is a scalar , is the number of space intervals
10 %- N is a scalar , is the number of time intervals
11 %- xi is a scalar , is the start point of the space domaine of integration
12 %- xf is a scalar , is the end point of the space domaine of integration
13 %- T is a scalar , is the end of the time domain of integration (0;T)
14 %- eta is a scalar , is a paramater of the differential equation
15 %- u0 is a cell u0 = @(x) ... which discribes the initial condition
16 %- ui is a cell ui = @(t) ... which discribes u(xi)=ui
17 %- uf is a cell uf = @(t) ... which discribes u(xf)=uf
18 %@POST:
19 %- uh is a (M+1)x(M+1) matrix , is the computed solution
20 %%
21 f unc t i on uh = DN2266_lab4_Q2cauchy(M,N,xi,xf ,T,eta ,u0 ,ui,uf)
22
23 dx = (xf -xi)/M;
24 dt = T/N;
25
26 xh = l i ns pac e (xi ,xf,M+1);
27 th = l i ns pac e (0,T,N+1);
28
29 uh = z e r os (M+1,N+1);
30
31 %u(t=0,x)
32 uh(:,1) = u0(xh);
33
34 %u(t,xi)=ui
35 uh(1,:) = ui(th);
36
37 %u(t,xf)=uf
38 uh(end ,:) = uf(th);
39
40 % figure
41 % plot(xh,uh(:,1) ,.-);
42 % yl = 1.5;
43 % xlabel(x);
44 % ylabel(u(t,x) );
45 % title([eta = num2str(eta), | Time = 0 [s]]);
46 % ylim([-yl ,yl])
47
48 %
49 da0 = -2*ones(1,M+1);
50 dad = ones(1,M+1);
51 A = s pdi ags ([dad;da0;dad],[-1,0,1],M-1,M-1);
52 a = [eta*(dt/(dx*dx))*ui(th(1)); z e r os (M-3,1);eta*(dt/(dx*dx))*uf(th(1))];
53 a = s par s e (a);
54
55 db1 = dad;
56 dbm1 = -db1;
57 B = s pdi ags ([dbm1;db1],[-1,1],M-1,M-1);
58 b = [(dt/(2*dx))*ui(th(1)); z e r os (M-3,1);-(dt/(2*dx))*uf(th(1))];
59 b = s par s e (b);
60
61
62
63 f o r n = 1 : N
64
31
65 uh(2:end-1,n+1) = uh(2:end-1,n) + (eta*(dt/(dx*dx))*A - (dt/(2*dx))*B)*uh(2:end-1,n)...
66 + a + b;
67
68 a(1) = eta*(dt/(dx*dx))*ui(th(n+1));
69 a(end)= a(1);
70 b(1) = (dt/(2*dx))*ui(th(n+1));
71 b(end)= -b(1);
72
73 % drawnow
74 % plot(xh,uh(:,n+1) ,.-);
75 % xlabel(x)
76 % ylabel(u(t;x) )
77 % title([eta = num2str(eta), | Time = num2str ((n-1)*T/N) ,[s]])
78 % grid on
79 % ylim([-yl ,yl])
80
81 end
82
83 f i g ur e ()
84 s ubpl ot (3,2,1)
85 pl ot (xh ,uh(:,2),.-);
86 xl abe l (x)
87 yl abe l (u(t;x))
88 t i t l e (Time = 0 [s],FontSize ,20)
89 gr i d on
90 %ylim([-yl,yl])
91 %
92 s ubpl ot (3,2,2)
93 pl ot (xh ,uh(:,round((N+1)/5) +1),.-);
94 xl abe l (x)
95 yl abe l (u(t;x))
96 t i t l e ([eta = num2str (eta), |Time = , num2str (T/N*(round((N+1)/5) -1)),[s]],FontSize
,20)
97 gr i d on
98 %ylim([-yl,yl])
99 %
100 s ubpl ot (3,2,3)
101 pl ot (xh ,uh(:,round(2*(N+1)/5)+1),.-);
102 xl abe l (x)
103 yl abe l (u(t;x))
104 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(2*(N+1)/5) -1)),[s]],FontSize
,20)
105 gr i d on
106 %ylim([-yl,yl])
107 %
108 s ubpl ot (3,2,4)
109 pl ot (xh ,uh(:,round(3*(N+1)/5)+1),.-);
110 xl abe l (x)
111 yl abe l (u(t;x))
112 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(3*(N+1)/5) -1)),[s]],FontSize
,20)
113 gr i d on
114 %ylim([-yl,yl])
115 %
116 s ubpl ot (3,2,5)
117 pl ot (xh ,uh(:,round(4*(N+1)/5)+1),.-);
118 xl abe l (x)
119 yl abe l (u(t;x))
120 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(4*(N+1)/5) -1)),[s]],FontSize
,20)
121 gr i d on
122 %ylim([-yl,yl])
123 %
124 s ubpl ot (3,2,6)
125 pl ot (xh ,uh(:,end),.-);
126 xl abe l (x)
127 yl abe l (u(t;x))
128 t i t l e ([eta = num2str (eta), | Time = , num2str (T),[s]],FontSize ,20)
129 gr i d on
130 %ylim([-yl,yl])
131
32
132 end
C DN2266_lab4_Q2cauchybis.m
1 %%
2 %DN2266_lab4_Q2cauchybis(M,N,xi,xf ,T,eta ,u0 ,ui,uf) solves the differential
3 %problem
4 %u_t + a*u_x = eta*u_xx
5 %with Dirichlet boundary conditions u(xi)=ui, u(xf)=uf
6 %by using central scheme for the space derivative of second order and unilateral for the
7 %time and space of first order.
8 %@PRE:
9 %- M is a scalar , is the number of space intervals
10 %- N is a scalar , is the number of time intervals
11 %- xi is a scalar , is the start point of the space domaine of integration
12 %- xf is a scalar , is the end point of the space domaine of integration
13 %- T is a scalar , is the end of the time domain of integration (0;T)
14 %- eta is a scalar , is a paramater of the differential equation
15 %- u0 is a cell u0 = @(x) ... which discribes the initial condition
16 %- ui is a cell ui = @(t) ... which discribes u(xi)=ui
17 %- uf is a cell uf = @(t) ... which discribes u(xf)=uf
18 %@POST:
19 %- uh is a (M+1)x(M+1) matrix , is the computed solution
20 %%
21
22 f unc t i on uh = DN2266_lab4_Q2cauchybis(M,N,xi ,xf,T,eta ,u0,ui,uf)
23
24 dx = (xf -xi)/M;
25 dt = T/N;
26
27 xh = l i ns pac e (xi ,xf,M+1);
28 th = l i ns pac e (0,T,N+1);
29
30 uh = z e r os (M+1,N+1);
31
32 %u(t=0,x)
33 uh(:,1) = u0(xh);
34
35 %u(t,xi)=ui
36 uh(1,:) = ui(th);
37
38 %u(t,xf)=uf
39 uh(end ,:) = uf(th);
40
41 % figure
42 % plot(xh,uh(:,1) ,.-);
43 % yl = 1.5;
44 % xlabel(x);
45 % ylabel(u(t,x) );
46 % title([eta = num2str(eta), | Time = 0 [s]]);
47 % ylim([-yl ,yl])
48
49 %
50 da0 = -2*ones(1,M+1);
51 dad = ones(1,M+1);
52 A = s pdi ags ([dad;da0;dad],[-1,0,1],M-1,M-1);
53 a = [eta*(dt/(dx*dx))*ui(th(1)); z e r os (M-3,1);eta*(dt/(dx*dx))*uf(th(1))];
54 a = s par s e (a);
55
56 db0 = dad;
57 dbm1 = -db0;
58 B = s pdi ags ([dbm1;db0],[-1,0],M-1,M-1);
59 b = [(dt/(2*dx))*ui(th(1)); z e r os (M-2,1)];
60 b = s par s e (b);
61
62
33
63
64 f o r n = 1 : N
65
66 uh(2:end-1,n+1) = uh(2:end-1,n) + (eta*(dt/(dx*dx))*A - (dt/(2*dx))*B)*uh(2:end-1,n)...
67 + a + b;
68
69 a(1) = eta*(dt/(dx*dx))*ui(th(n+1));
70 a(end)= a(1);
71 b(1) = (dt/(2*dx))*ui(th(n+1));
72 b(end)= -b(1);
73
74 % drawnow
75 % plot(xh,uh(:,n+1) ,.-);
76 % xlabel(x)
77 % ylabel(u(t;x) )
78 % title([eta = num2str(eta), | Time = num2str ((n-1)*T/N) ,[s]])
79 % grid on
80 % ylim([-yl ,yl])
81
82 end
83
84 f i g ur e ()
85 s ubpl ot (3,2,1)
86 pl ot (xh ,uh(:,2),.-);
87 xl abe l (x)
88 yl abe l (u(t;x))
89 t i t l e (Time = 0 [s],FontSize ,20)
90 gr i d on
91 %ylim([-yl,yl])
92 %
93 s ubpl ot (3,2,2)
94 pl ot (xh ,uh(:,round((N+1)/5) +1),.-);
95 xl abe l (x)
96 yl abe l (u(t;x))
97 t i t l e ([eta = num2str (eta), |Time = , num2str (T/N*(round((N+1)/5) -1)),[s]],FontSize
,20)
98 gr i d on
99 %ylim([-yl,yl])
100 %
101 s ubpl ot (3,2,3)
102 pl ot (xh ,uh(:,round(2*(N+1)/5)+1),.-);
103 xl abe l (x)
104 yl abe l (u(t;x))
105 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(2*(N+1)/5) -1)),[s]],FontSize
,20)
106 gr i d on
107 %ylim([-yl,yl])
108 %
109 s ubpl ot (3,2,4)
110 pl ot (xh ,uh(:,round(3*(N+1)/5)+1),.-);
111 xl abe l (x)
112 yl abe l (u(t;x))
113 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(3*(N+1)/5) -1)),[s]],FontSize
,20)
114 gr i d on
115 %ylim([-yl,yl])
116 %
117 s ubpl ot (3,2,5)
118 pl ot (xh ,uh(:,round(4*(N+1)/5)+1),.-);
119 xl abe l (x)
120 yl abe l (u(t;x))
121 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(4*(N+1)/5) -1)),[s]],FontSize
,20)
122 gr i d on
123 %ylim([-yl,yl])
124 %
125 s ubpl ot (3,2,6)
126 pl ot (xh ,uh(:,end),.-);
127 xl abe l (x)
128 yl abe l (u(t;x))
129 t i t l e ([eta = num2str (eta), | Time = , num2str (T),[s]],FontSize ,20)
34
130 gr i d on
131 %ylim([-yl,yl])
132
133 end
D DN2266_lab4_Q2c.m
1 %%
2 %DN2266_lab4_Q2c(M,N,xi,xf,T,eta ,u0,ui,uf) solves for x in (0;2*pi) the
3 %differential problem
4 %u_t + a*u_x = eta*u_xx
5 %with Dirichlet boundary conditions u(xi)=ui, u(xf)=uf
6 %by using central scheme for the space derivatives and unilateral for the
7 %time.
8 %@PRE:
9 %- M is a scalar , is the number of space intervals
10 %- N is a scalar , is the number of time intervals
11 %- T is a scalar , is the end of the time domain of integration (0;T)
12 %- eta is a scalar , is a paramater of the differential equation
13 %- u0 is a cell u0 = @(x) ... which discribes the initial condition
14 %@POST:
15 %- uh is a (M+1)x(M+1) matrix , is the computed solution
16 %%
17 f unc t i on uh = DN2266_lab4_Q2c(M,N,T,eta ,u0)
18
19 dx = 2* pi /M;
20 dt = T/N;
21
22 xh = l i ns pac e (0,2* pi ,M+1);
23 %th = linspace(0,T,N+1);
24
25 uh = z e r os (M+1,N+1);
26
27 %u(t=0,x)
28 uh(:,1) = u0(xh);
29
30 % figure
31 % plot(xh,uh(:,1) ,.-);
32 yl = 1.5;
33 % xlabel(x);
34 % ylabel(u(t,x) );
35 % title([eta = num2str(eta), | Time = 0 [s]]);
36 % ylim([-yl ,yl])
37
38 %
39 da0 = -2*ones(1,M+1);
40 dad = ones(1,M+1);
41 A = s pdi ags ([dad;da0;dad],[-1,0,1],M+1,M+1);
42 A(1,M) = 1;
43 A(M+1,2) = 1;
44
45 db1 = dad;
46 dbm1 = -db1;
47 B = s pdi ags ([dbm1;db1],[-1,1],M+1,M+1);
48 B(1,M) = -1;
49 B(M+1,2) = 1;
50
51
52
53
54 f o r n = 1 : N
55
56 uh(:,n+1) = uh(:,n) + (eta*(dt/(dx*dx))*A - (dt/(2*dx))*B)*uh(:,n);
57
58 % drawnow
59 % plot(xh,uh(:,n+1) ,.-);
35
60 % xlabel(x)
61 % ylabel(u(t;x) )
62 % title([eta = num2str(eta), | Time = num2str ((n-1)*T/N) ,[s]])
63 % grid on
64 % ylim([-yl ,yl])
65
66 end
67
68 f i g ur e ()
69 s ubpl ot (3,2,1)
70 pl ot (xh ,uh(:,2),.-);
71 xl abe l (x)
72 yl abe l (u(t;x))
73 t i t l e (Time = 0 [s],FontSize ,20)
74 gr i d on
75 ylim([-yl,yl])
76 %
77 s ubpl ot (3,2,2)
78 pl ot (xh ,uh(:,round((N+1)/5) +1),.-);
79 xl abe l (x)
80 yl abe l (u(t;x))
81 t i t l e ([eta = num2str (eta), |Time = , num2str (T/N*(round((N+1)/5) -1)),[s]],FontSize
,20)
82 gr i d on
83 ylim([-yl,yl])
84 %
85 s ubpl ot (3,2,3)
86 pl ot (xh ,uh(:,round(2*(N+1)/5)+1),.-);
87 xl abe l (x)
88 yl abe l (u(t;x))
89 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(2*(N+1)/5) -1)),[s]],FontSize
,20)
90 gr i d on
91 %ylim([-yl,yl])
92 %
93 s ubpl ot (3,2,4)
94 pl ot (xh ,uh(:,round(3*(N+1)/5)+1),.-);
95 xl abe l (x)
96 yl abe l (u(t;x))
97 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(3*(N+1)/5) -1)),[s]],FontSize
,20)
98 gr i d on
99 ylim([-yl,yl])
100 %
101 s ubpl ot (3,2,5)
102 pl ot (xh ,uh(:,round(4*(N+1)/5)+1),.-);
103 xl abe l (x)
104 yl abe l (u(t;x))
105 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(4*(N+1)/5) -1)),[s]],FontSize
,20)
106 gr i d on
107 ylim([-yl,yl])
108 %
109 s ubpl ot (3,2,6)
110 pl ot (xh ,uh(:,end),.-);
111 xl abe l (x)
112 yl abe l (u(t;x))
113 t i t l e ([eta = num2str (eta), | Time = , num2str (T),[s]],FontSize ,20)
114 gr i d on
115 ylim([-yl,yl])
116
117 end
E DN2266_lab4_Q2cbis.m
1 %%
36
2 %DN2266_lab4_Q2cbis(M,N,xi,xf ,T,eta ,u0,ui,uf) solves for x in (0;2* pi)
3 %the differential problem
4 %u_t + a*u_x = eta*u_xx
5 %u(x) = u(x+2*pi)
6 %by using central scheme for the space derivative of second order and unilateral
7 %for the time and space of first order.
8 %@PRE:
9 %- M is a scalar , is the number of space intervals
10 %- N is a scalar , is the number of time intervals
11 %- T is a scalar , is the end of the time domain of integration (0;T)
12 %- eta is a scalar , is a paramater of the differential equation
13 %- u0 is a cell u0 = @(x) ... which discribes the initial condition
14 %@POST:
15 %- uh is a (M+1)x(M+1) matrix , is the computed solution
16 %%
17 f unc t i on uh = DN2266_lab4_Q2cbis(M,N,T,eta ,u0)
18
19 dx = 2* pi /M;
20 dt = T/N;
21
22 xh = l i ns pac e (0,2* pi ,M+1);
23 %th = linspace(0,T,N+1);
24
25 uh = z e r os (M+1,N+1);
26
27 %u(t=0,x)
28 uh(:,1) = u0(xh);
29
30 % figure
31 % plot(xh,uh(:,1) ,.-);
32 yl = 1.5;
33 % xlabel(x);
34 % ylabel(u(t,x) );
35 % title([eta = num2str(eta), | Time = 0 [s]]);
36 % ylim([-yl ,yl])
37
38 %
39 da0 = -2*ones(1,M+1);
40 dad = ones(1,M+1);
41 A = s pdi ags ([dad;da0;dad],[-1,0,1],M+1,M+1);
42 A(1,M) = 1;
43 A(M+1,2) = 1;
44
45 db0 = dad;
46 dbm1 = -db0;
47 B = s pdi ags ([dbm1;db0],[-1,0],M+1,M+1);
48 B(1,M) = -1;
49
50
51
52 f o r n = 1 : N
53
54 uh(:,n+1) = uh(:,n) + (eta*(dt/(dx*dx))*A - (dt/dx)*B)*uh(:,n);
55
56 % drawnow
57 % plot(xh,uh(:,n+1) ,.-);
58 % xlabel(x)
59 % ylabel(u(t;x) )
60 % title([eta = num2str(eta), | Time = num2str ((n-1)*T/N) ,[s]])
61 % grid on
62 % ylim([-yl ,yl])
63
64 end
65
66 f i g ur e ()
67 s ubpl ot (3,2,1)
68 pl ot (xh ,uh(:,2),.-);
69 xl abe l (x)
70 yl abe l (u(t;x))
71 t i t l e (Time = 0 [s],FontSize ,20)
72 gr i d on
37
73 ylim([-yl,yl])
74 %
75 s ubpl ot (3,2,2)
76 pl ot (xh ,uh(:,round((N+1)/5) +1),.-);
77 xl abe l (x)
78 yl abe l (u(t;x))
79 t i t l e ([eta = num2str (eta), |Time = , num2str (T/N*(round((N+1)/5) -1)),[s]],FontSize
,20)
80 gr i d on
81 ylim([-yl,yl])
82 %
83 s ubpl ot (3,2,3)
84 pl ot (xh ,uh(:,round(2*(N+1)/5)+1),.-);
85 xl abe l (x)
86 yl abe l (u(t;x))
87 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(2*(N+1)/5) -1)),[s]],FontSize
,20)
88 gr i d on
89 %ylim([-yl,yl])
90 %
91 s ubpl ot (3,2,4)
92 pl ot (xh ,uh(:,round(3*(N+1)/5)+1),.-);
93 xl abe l (x)
94 yl abe l (u(t;x))
95 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(3*(N+1)/5) -1)),[s]],FontSize
,20)
96 gr i d on
97 ylim([-yl,yl])
98 %
99 s ubpl ot (3,2,5)
100 pl ot (xh ,uh(:,round(4*(N+1)/5)+1),.-);
101 xl abe l (x)
102 yl abe l (u(t;x))
103 t i t l e ([eta = num2str (eta), | Time = , num2str (T/N*(round(4*(N+1)/5) -1)),[s]],FontSize
,20)
104 gr i d on
105 ylim([-yl,yl])
106 %
107 s ubpl ot (3,2,6)
108 pl ot (xh ,uh(:,end),.-);
109 xl abe l (x)
110 yl abe l (u(t;x))
111 t i t l e ([eta = num2str (eta), | Time = , num2str (T),[s]],FontSize ,20)
112 gr i d on
113 ylim([-yl,yl])
114
115 end
F DN2266_lab4_Q3a.m
1 %%
2 %DN2266_lab4_Q3a(M,N,X,T) solves the hyperbolic differential equation u_tt
3 %= u_xx for some initial conditions and boundary conditions.
4 %
5 %@PRE:
6 %- M is a scalar , is the number of space intervals
7 %- N is a scalar , is the number of time intervals
8 %- X is a scalar , is the end of the space domain of integration (0;X)
9 %- T is a scalar , is the end of the time domain of integration (0;T)
10 %@POST:
11 %- uh is a (M+1)x(N+1) matrix , which is the computed solution by the
12 %function
13 %%
14 f unc t i on uh = DN2266_lab4_Q3a(M,N,X,T)
15
16 dx = X/M;
38
17 dt = T/N;
18
19 beta = (dt/dx)^2
20
21 xs = .5;
22 u0 = @(x) exp( -100*(x-xs).^2);
23 um1 = @(x).5*(u0(x-dt) + u0(x+dt));
24
25 uh = z e r os (M+1,N+2); %uh(x,t)
26
27 xh = l i ns pac e (0,X,M+1);
28 %th = linspace(0,T,N+1);
29
30 % initial conditions
31 uh(:,1) = um1(xh); %t=-dt
32 uh(:,2) = u0(xh); %t=0
33
34 % boundary conditions
35 % uh(1,:) = uh(end ,:) = 0
36
37 d0 = -2*ones(1,M-1);
38 d = ones(1,M-1);
39
40 A = s pdi ags ([d;d0;d],[-1,0,1],M-1,M-1);
41
42 f i g ur e (1)
43 pl ot (xh ,uh(:,2) ,.-);
44 xl abe l (x)
45 yl abe l (u(t;x))
46 t i t l e ([Time = 0 [s]])
47 gr i d on
48 axi s equal
49
50 f o r n = 3 : N+2
51
52 uh(2:end-1,n) = beta * A * uh(2:end-1,n-1) + 2 * uh(2:end-1,n-1) - uh(2:end-1,n-2);
53
54 f i g ur e (1)
55 pl ot (xh ,uh(:,n),.-);
56 xl abe l (x)
57 yl abe l (u(t;x))
58 t i t l e ([Time = num2str ((n-2)*T/N),[s]])
59 gr i d on
60 ylim ([-1,1])
61 %pause (.001)
62
63 end
64
65 f i g ur e (2)
66 s ubpl ot (3,2,1)
67 pl ot (xh ,uh(:,2),.-);
68 xl abe l (x)
69 yl abe l (u(t;x))
70 t i t l e (Time = 0 [s],FontSize ,20)
71 gr i d on
72 axi s equal
73 %
74 s ubpl ot (3,2,2)
75 pl ot (xh ,uh(:,round((N+1)/5) +1),.-);
76 xl abe l (x)
77 yl abe l (u(t;x))
78 t i t l e ([Time = , num2str (T/N*(round((N+1)/5) -1)),[s]],FontSize ,20)
79 gr i d on
80 axi s equal
81 %
82 s ubpl ot (3,2,3)
83 pl ot (xh ,uh(:,round(2*(N+1)/5)+1),.-);
84 xl abe l (x)
85 yl abe l (u(t;x))
86 t i t l e ([Time = , num2str (T/N*(round(2*(N+1)/5) -1)),[s]],FontSize ,20)
87 gr i d on
39
88 axi s equal
89 %
90 s ubpl ot (3,2,4)
91 pl ot (xh ,uh(:,round(3*(N+1)/5)+1),.-);
92 xl abe l (x)
93 yl abe l (u(t;x))
94 t i t l e ([Time = , num2str (T/N*(round(3*(N+1)/5) -1)),[s]],FontSize ,20)
95 gr i d on
96 axi s equal
97 %
98 s ubpl ot (3,2,5)
99 pl ot (xh ,uh(:,round(4*(N+1)/5)+1),.-);
100 xl abe l (x)
101 yl abe l (u(t;x))
102 t i t l e ([Time = , num2str (T/N*(round(4*(N+1)/5) -1)),[s]],FontSize ,20)
103 gr i d on
104 axi s equal
105 %
106 s ubpl ot (3,2,6)
107 pl ot (xh ,uh(:,end),.-);
108 xl abe l (x)
109 yl abe l (u(t;x))
110 t i t l e ([Time = , num2str (T),[s]],FontSize ,20)
111 gr i d on
112 axi s equal
113
114
115 end
G DN2266_lab4_Q3b.m
1 %%
2 %DN2266_lab4_Q3b(M,N,X,T,d,g) solves the wave equation for a flute
3 %u_tt - u_xx + d*u = g
4 %u(t<=0) = 0
5 %u(x={0;X}) = 0
6 %
7 %@PRE:
8 %- M is a scalar , is the number of space intervals
9 %- N is a scalar , is the number of time intervals
10 %- X is a scalar , is the end of the space domain of integration (0;X)
11 %- T is a scalar , is the end of the time domain of integration (0;T)
12 %- d is a cell such that d = @(x) ...
13 %- g is a cell such that g = @(t;x) ...
14 %@POST:
15 %- zh is 1x(M+1) vector , is the solution through the time for x=X/4;
16 %- A is a (M-1)x(M-1) matrix , is the discrete operator of u_xx = Au
17 %- D is a (M-1)x(M-1) matrix , is the discrete operator of d*u = B*u
18 %%
19 f unc t i on [zh ,A,D] = DN2266_lab4_Q3b(M,N,X,T,d,g)
20
21 dx = X/M;
22 dt = T/N;
23
24 beta = (dt/dx)^2
25
26
27 uh = z e r os (M+1,N+2); %uh(x,t)
28 zh = z e r os (1,N+1);
29
30 xh = l i ns pac e (0,X,M+1);
31 th = l i ns pac e (0,T,N+1);
32
33
34 % boundary conditions
35 % uh(1,:) = uh(end ,:) = 0
40
36
37 d0 = -2*ones(1,M-1);
38 dd = ones(1,M-1);
39
40 A = s pdi ags ([dd;d0;dd],[-1,0,1],M-1,M-1);
41 D = s pdi ags (d(xh(2:end -1)),0,M-1,M-1);
42
43
44 % figure
45 % plot(xh,uh(:,2) ,.-);
46 % xlabel(x)
47 % ylabel(u(t;x) )
48 % title(Time = 0 [s])
49 % grid on
50 % yl = .1;
51 % ylim([-yl ,yl])
52
53 f o r n = 3 : N+2
54
55
56 uh(2:end-1,n) = beta * A * uh(2:end-1,n-1)...
57 + 2 * uh(2:end-1,n-1) - uh(2:end-1,n-2) ...
58 + (dt^2) * ((g(th(n-2),xh(2:end -1))) - (D * uh(2:end-1,n-1)));
59
60 zh(n-1) = uh( f l o o r (X/4*M)+1,n); % x = .25
61
62 % drawnow
63 % plot(xh,uh(:,n) ,.-);
64 % xlabel(x)
65 % ylabel(u(t;x) )
66 % title([Time = num2str ((n-2)*T/N),[s]])
67 % grid on
68 % ylim([-yl ,yl])
69
70 end
71
72 % figure ()
73 % subplot (3,2,1)
74 % plot(xh,uh(:,2) ,.-);
75 % xlabel(x)
76 % ylabel(u(t;x) )
77 % title(Time = 0 [s],FontSize ,20)
78 % grid on
79 % ylim([-yl ,yl])
80 % %
81 % subplot (3,2,2)
82 % plot(xh,uh(:,round((N+1)/5)+1) ,.-);
83 % xlabel(x)
84 % ylabel(u(t;x) )
85 % title([Time = , num2str(T/N*(round ((N+1)/5) -1)),[s]],FontSize ,20)
86 % grid on
87 % ylim([-yl ,yl])
88 % %
89 % subplot (3,2,3)
90 % plot(xh,uh(:,round (2*(N+1)/5)+1) ,.-);
91 % xlabel(x)
92 % ylabel(u(t;x) )
93 % title([Time = , num2str(T/N*(round (2*(N+1)/5) -1)),[s]],FontSize ,20)
94 % grid on
95 % ylim([-yl ,yl])
96 % %
97 % subplot (3,2,4)
98 % plot(xh,uh(:,round (3*(N+1)/5)+1) ,.-);
99 % xlabel(x)
100 % ylabel(u(t;x) )
101 % title([Time = , num2str(T/N*(round (3*(N+1)/5) -1)),[s]],FontSize ,20)
102 % grid on
103 % ylim([-yl ,yl])
104 % %
105 % subplot (3,2,5)
106 % plot(xh,uh(:,round (4*(N+1)/5)+1) ,.-);
41
107 % xlabel(x)
108 % ylabel(u(t;x) )
109 % title([Time = , num2str(T/N*(round (4*(N+1)/5) -1)),[s]],FontSize ,20)
110 % grid on
111 % ylim([-yl ,yl])
112 % %
113 % subplot (3,2,6)
114 % plot(xh,uh(:,end) ,.-);
115 % xlabel(x)
116 % ylabel(u(t;x) )
117 % title([Time = , num2str(T) ,[s]],FontSize ,20)
118 % grid on
119 % ylim([-yl ,yl])
120
121 A = A/(dx*dx);
122
123
124
125 end
42

Das könnte Ihnen auch gefallen