-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathddyc.m
32 lines (26 loc) · 941 Bytes
/
ddyc.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
function dfdy = ddyc(f,dy)
% Calculates central-difference derivative wrt y on even-spaced 2D grid
%
% INPUTS
% f = [ny,nx double] array with function values
% dy = [double] grid spacing
%
% OUTPUTS
% dfdy = [ny,nx double] array with function derivatives
%
% ny and nx are the number of x and y grid points, respectively. It is
% assumed that the 2D grid is created using the meshgrid() function.
% Anthony Ricciardi
% July 2021
[ny,nx] = size(f);
inY = 2:ny-1; % interior y
% initialize
dfdy = zeros(ny,nx);
% central difference interior points [O(dy^2)]
dfdy(inY,:) = (f(inY+1,:) - f(inY-1,:))./(2*dy);
% % one-sided difference boundary points [O(dy)]
dfdy(1,:) = (f(2,:) - f(1,:))./(dy);
dfdy(ny,:) = (f(ny,:) - f(ny-1,:))./(dy);
% one-sided difference boundary points [O(dy^2)]
% dfdy(1,:) = (-f(3,:) + 4*f(2,:) - 3*f(1,:))./(2*dy);
% dfdy(ny,:) = (3*f(ny,:) - 4*f(ny-1,:) + f(ny-2,:))./(2*dy);