Matlab help: inverting the linear water waves dispersion relation J. Rabault

advertisement
Matlab help: inverting the linear water
waves dispersion relation
J. Rabault
9th February 2016
Here is a little example of how to use the fsolve Matlab function to numerically inverse the
dispersion relation for deep water waves: ω 2 = g.k.tanh(kh). The following code should be
run from a script:
1
2
clear all;
close all;
3
4
%% global parameters
5
6
7
g = 9.81;
h = 0.7;
% water depth
8
9
10
11
% suppressing text output from fsolve
% note: this is dangerous, only if sure of what I do...
options = optimset('Display','off');
12
13
%% compute the angular frequency, wave number, wave length from frequency
14
15
16
fprintf('Condition is imposed frequency: ');
fprintf('\n');
17
18
19
frequency = 1.5;
omega = 2*pi*frequency;
% frequency in Hertz
% angular frequency rad / s
20
21
22
23
24
25
26
27
28
29
30
31
32
33
% compute the wave number from dispersion relation
% global variables are temporarily used to pass arguments
global gGlobal;
global hGlobal;
global omegaGlobal;
gGlobal = g;
hGlobal = h;
omegaGlobal = omega;
[k]=fsolve(@DispersionRelationWithArgs,1,options);
clear gGlobal;
clear hGlobal;
clear omegaGlobal;
lambda = 2*pi/k;
34
35
36
fprintf('wave length lambda (m) %d',lambda);
fprintf('\n');
1
Matlab help: fsolve
And you should have in the same folder a function called DispersionRelationWithArgs,
containing the following code:
1
function [ OmegaRes ] = DispersionRelationWithArgs(k)
2
3
4
5
global gGlobal;
global hGlobal;
global omegaGlobal;
6
7
8
9
% Dispersion relation for linear waves
% g and h are given as global variables (for inverse
% problem solving with only one argument).
10
11
12
13
14
%
%
%
%
OmegaRes the residual to make equal to zero
omegaGlobal the omega for which k should be computed
k the wave number
gGlobal, hGlobal given as global
15
16
OmegaRes = sqrt(gGlobal*k*tanh(k*hGlobal))-omegaGlobal;
17
18
end
J. Rabault
2
Download