-
Notifications
You must be signed in to change notification settings - Fork 31
/
addmup.m
48 lines (45 loc) · 1.4 KB
/
addmup.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
function nrmorl=addmup(nr,drk)
% nrmorl=ADDMUP(nr,drk)
%
% Calculates the number of real spherical harmonic ORDERS that belong to
% an expansion from DEGREE l=0 to L, OR vice versa. For arrays where m=0:l.
%
% INPUT:
%
% nr The number of real spherical harmonic orders, OR
% The degree of the expansion
% drk 'a' the input is the degree, calculate the number [default]
% 'r' the input is the number, calculate the degree
%
% OUTPUT:
%
% nrmorl The degree of the expansion, OR
% The number of real spherical harmonic orders
%
% NOTE:
%
% addmup(-1) equals 0, which is just as well
%
% See also ADDMOFF, ADDMOUT
%
% Last modified by fjsimons-at-alum.mit.edu, 05/11/2021
% Since m=0:l for real spherical harmonics, the number of orders per
% degree is l+1. This program thus calculates
% $\sum\limits_{l=0}^{L}(l+1)$ and its inverse, for a given L, using
% analytical expressions. Works for matrices, vectors as well as
% scalars. Note: degrees 0 and 1 are of course included in the count.
% Check the behavior for the negatives should you ever need those
defval('nr',3)
defval('drk','a')
switch drk
case 'a'
nrmorl=1/2*(nr+1).^2+1/2*nr+1/2;
% nrmorl=1/2*nr.^2+3/2*nr+1;
case 'r'
nrmorl=-3/2+1/2*sqrt(1+8*nr);
if prod((round(nrmorl)==nrmorl)+0)==0
warning('Invalid entry - noninteger result')
end
otherwise
error('Specify a valid option')
end