-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvald.m
62 lines (44 loc) · 1.19 KB
/
dvald.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
function [dval] = dvald(val, hx, hy, ht, S, delta_z)
% Finds the first derivative of 'val' in either x and y.
% Centred difference for x and y.
nx = size(val,1); ny = size(val,2);
if nargin==5
dval = zeros(nx,ny);
if strcmp(S,'x') % x derivative
for i = 2:nx-1
for j = 1:ny
dval(i,j) = (val(i+1,j)-val(i-1,j))/(2*hx*1e+3);
end
end
for j = 1:ny
dval(1,j) = (val(2,j)-val(nx,j))/(2*hx*1e+3);
dval(nx,j) = (val(1,j)-val(nx-1,j))/(2*hx*1e+3);
end
elseif strcmp(S,'y') % y derivative
for i = 1:nx
for j = 2:ny-1
dval(i,j) = (val(i,j+1)-val(i,j-1))/(2*hy*1e+3);
end
end
for i = 1:nx
dval(i,1) = (val(i,2)-val(i,ny))/(2*hy*1e+3);
dval(i,ny) = (val(i,1)-val(i,ny-1))/(2*hy*1e+3);
end
elseif strcmp(S, 't')
for i = 1:nx
for j = 1:ny
dval(i,j) = (val(i,j,2)-val(i,j,1))/(ht);
end
end
end
else
if strcmp(S, 'z') % z derivative
nz = size(val,3);
dval = zeros(nx,ny,nz);
for k = 1:nz-1
dval(:,:,k) = (val(:,:,k)-val(:,:,k+1))/delta_z(k);
end
dval(:,:,nz) = val(:,:,nz)/delta_z(nz);
end
end
end