-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdispersion.m
65 lines (65 loc) · 2.07 KB
/
dispersion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%% dispersion.m
function kh=dispersion(const)
%%
% Solution of the linear dispersion relationship for surface gravity waves.
% The solution satisfies const=kh*tanh(kh) within 1e-06.
% It is obtained using the Newton-Raphson iteration method.
% The input values of const should be zero or positive;
% the routine returns kh = NaN for negative values of const.
%
%% Usage:
% kh = dispersion(const)
%
%% Input:
% const = vector of omega^2*h/g
% where omega = radian frequency,
% h = water depth,
% g = acceleration due to gravity, and
%
%% Output:
% kh = vector of k*h
% where k = wavenumber.
%
%% Authors
% George Voulgaris
% School of the Earth, Ocean and Environment
% University of South Carolina, Columbia, SC, USA
%
% based on a function first developed by John Trowbridge (WHOI) circa 1999
%
%% Copyright 2019 George Voulgaris
%
% This file is part of WavePart.
%
% WavePart is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%
echo off
% initialize kh
kh = NaN*ones(size(const));
% solution for zero values of const
m = find(const==0);
kh(m) = zeros(size(m));
% initial value for positive const
m = find(const>0);
kh(m) = sqrt(const(m));
m = find(const>1);
kh(m) = const(m);
% iterative solution for positive const
m = find(const>0);
while max(abs(const(m) - kh(m).*tanh(kh(m))))>1e-06
f = kh(m).*tanh(kh(m)) - const(m);
fprime = kh(m)./cosh(kh(m)).^2 + tanh(kh(m));
kh(m) = kh(m) - f./fprime;
end
end