Beruflich Dokumente
Kultur Dokumente
ving 10 - Matlab
@ 2 P (x z t) + @ 2 P (x z t) = 1 @ 2 P (x z t) + S (x z t)
(1)
@x2
@z2
c2(x z) @t2
where c(x z) is the wave-velocity and S (x z t) is a source term
We shall replace the di erential equation (1) with a nite di erence equation being an
approximation to equation (1). The nite di erence equation can be rearranged, enabling
us to nd the pressure at the next time step as a function of the pressure at present and
previous timesteps.
@P (x z t) = lim P (x + x z t) ; P (x z t)
x!0
@x
x
Allowing x to be nite rather than in nitesimal yields the approximation:
@P (x z t) P (x + x z t) ; P (x z t)
@x
x
The second derivative is obtained by repeating the above procedure.
Norges teknisk-naturvitenskapelige universitet
Institutt for petroleumsteknologi og anvendt geofysikk
@ 2 P (x z t) = @ @P (x z t)
@x2
@x @x
@P (x+ x z t)
@x
; @P (@xx z t)
(P (x + 2 x z t) ; P (x + x z t)) ; (P (x + x z t) ; P (x z t))
x2
we may perform a backward shift x resulting in:
@ 2 P (x z t) P (x + x z t) ; 2P (x z t) + P (x ; x z t)
@x2
x2
We introduce a more compact notation.
P (x z t) ) Plnm = P (l x m z n t)
c(x z) ) cl m = c(l x m z)
S (x z t) ) Slnm = S (l x m z n t)
(2)
(3)
(4)
(5)
Part 1:
Make a Matlab program that gives the pressure eld as a function of x and z at time
0.2 s, n=200 and plot the result. Use equation (7)
Let x = y = 4m and let t = 0:001s. m and l should cover a 200x200 grid-area.
Assume a constant wave
velocity of c0 = 1500 m/s (The velocity of sound in water).
2 t2
c
(It is important that m x2 < 21 Otherwise the error will increase for each timestep
causing instability.)
n
n
n
Boundary conditions are P0nm = P200
m = Pl 0 = Pl 200 = 0, while the initial conditions are
given by
Pl0m = 0
(8)
Pl1m = 0
(9)
a)
n+1
n1
Figure 1: Finite di erence grid. The pressure at the star is calculated from the values of
the pressure at the dots
To generate the waves we use a source Slnm de ned by
n
S100
100 = f (n)
Slnm = 0 else
(10)
(11)
Part 2:
Repeat part 1a) and b), but insert a re ector along m=120 by letting the velocity be
2000 m/s above m=120.
Matlab commands
The pc-version of Matlab is started by clicking the matlab-icon or writing matlab in the
run window. The Unix version is started from the dtterm window or xterm window with
Norges teknisk-naturvitenskapelige universitet
Institutt for petroleumsteknologi og anvendt geofysikk
the command matlab. Writing quit at the Matlab prompt will terminate the session.
Documentation for all matlab commands is obtained writing help command The current
working directory can be found with the command pwd. You may change directory to e.g.
c:\yourdirectory (assuming pc-matlab) using the command
cd c:\yourdirectory
load c:\yourdirectory\kilde
x has the same number of components as kilde (which is important). This number is
found with the length command. The component-values are
1/1000,2/1000,3/1000,4/1000.... The semicolon prevents these values from being
displayed on the screen We specify the x-coordinate by issuing two input vectors for the
plot command: x and kilde. Two more vectors will be interpreted as a new
x-coordinate/y-coordinate pair yielding two curves
plot(x,kilde)
plot(x,kilde,x,kilde+1)
Two curves
Vectors can be created 'manually' by writing the component values between brackets
0 1 0 3 4 3]
kilde(1:5) 0 0 kilde(6:10)])
The axis is
The rows of the matrix are separated by semicolons. This can be plotted using for
instance
mesh(matrise) or
contour(matrise)
Loops are constructed similarly to other programming languages. It can be done like this
for k=1:20, energi(k)=kilde(k)*kilde(k) end
energi(k)=kilde(k).*kilde(k)
Placing a period before the multiplication sign ensures that multiplication is carried out
component by component. The last alternative is much faster than the for-end alternative
Conditional statements are implemented this way
if (x==0), y=0 end
x is tested for equality with zero (note two equal signs). If this is true, y is assigned the
value zero. In the next example x has to be di erent from zero and z has to be less than
8 for the operation y=0 to be carried out
'&'
corresponds to 'or'.
500
450
400
350
300
250
200
150
100
50
50
100
150
200
250
300
350
400
450
500
50
100
150
Tid
200
250
300
350
400
450
500
50
100
150
200
250
300
350
400
450
500
500
450
400
350
300
250
200
150
100
50
50
100
150
200
250
300
350
400
450
500
50
100
150
Tid
200
250
300
350
400
450
500
50
100
150
200
250
300
350
400
450
500
Figure 5: Arrival times for di erent x values, z=250, direct wave and re ection.