-
Notifications
You must be signed in to change notification settings - Fork 0
/
evalPhi.m
45 lines (38 loc) · 1.11 KB
/
evalPhi.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
function [phi] = evalPhi( r );
%
% [phi] = evalPhi( r );
%
% Calculates phi( r ), phi the discrete delta function (without scaling)
%
% Returns:
% phi = value of unscaled discrete delta function at each point, r
%
% Input:
% r = the points to evaluate the discrete delta function at
%
% Note:
% This code doesn't handle wrapping across periodic boundaries.
%
%
% License: This code is free to use for any purposes, provided
% any publications resulting from the use of this code
% reference the original code/author.
%
% Author: Samuel Isaacson ([email protected])
% Date: 11/2007
%
% Please notify the author of any bugs, and contribute any
% modifications or bug fixes back to the original author.
%
% Disclaimer:
% This code is provided as is. The author takes no responsibility
% for its results or effects.
phi = zeros(length(r), 1);
aR = abs( r );
idx1 = find( aR < 1 );
idx2 = find( aR >= 1 );
rT = aR(idx1);
phi(idx1) = 3 - 2*rT + sqrt( 1 + 4*rT - 4*rT.*rT );
rT = aR(idx2);
phi(idx2) = 5 - 2*rT - sqrt( -7 + 12*rT - 4*rT.*rT );
phi = phi / 8;