function z = zernpol(n,m,r,nflag) ! 6p)t[s
%ZERNPOL Radial Zernike polynomials of order N and frequency M. jnU*l\,
% Z = ZERNPOL(N,M,R) returns the radial Zernike polynomials of [o[v"e\w
% order N and frequency M, evaluated at R. N is a vector of 7n\j"0z
% positive integers (including 0), and M is a vector with the {'c%#\
% same number of elements as N. Each element k of M must be a @KXz4PU
% positive integer, with possible values M(k) = 0,2,4,...,N(k) 02# b:
% for N(k) even, and M(k) = 1,3,5,...,N(k) for N(k) odd. R is } TX'Z?Lq
% a vector of numbers between 0 and 1. The output Z is a matrix jy__Y=1}
% with one column for every (N,M) pair, and one row for every T^(n+ lv
% element in R. y_7XYT!w
% %<ptkZK#
% Z = ZERNPOL(N,M,R,'norm') returns the normalized Zernike poly- }^GV(]K
% nomials. The normalization factor Nnm = sqrt(2*(n+1)) is TgQ|T57
% chosen so that the integral of (r * [Znm(r)]^2) from r=0 to ?%za:{
% r=1 is unity. For the non-normalized polynomials, Znm(r=1)=1 Z:B Y*#B
% for all [n,m]. .X<"pd*@e
% Nz>E#.++
% The radial Zernike polynomials are the radial portion of the qK6
uU9z
% Zernike functions, which are an orthogonal basis on the unit s:jL/%+COZ
% circle. The series representation of the radial Zernike tN'- qdm
% polynomials is E/L?D
% CK!pH{n+
% (n-m)/2 dl7p1Cr
% __ &J&w4"0N'
% m \ s n-2s ?/l}(t$H
% Z(r) = /__ (-1) [(n-s)!/(s!((n-m)/2-s)!((n+m)/2-s)!)] * r K3r>nGLBo
% n s=0 wkZ2Y-#='
% ZAo)_za&mH
% The following table shows the first 12 polynomials. i:Z.;z$1
% t6L^
#\'
% n m Zernike polynomial Normalization xBI"{nGoN
% --------------------------------------------- T`'3Cp$q
% 0 0 1 sqrt(2) c;|&>Fp
% 1 1 r 2 k0e|8g X
% 2 0 2*r^2 - 1 sqrt(6) ++{+
#s6
% 2 2 r^2 sqrt(6) _9O }d
% 3 1 3*r^3 - 2*r sqrt(8) b1>$sPJ+
% 3 3 r^3 sqrt(8) kDpZnXP
% 4 0 6*r^4 - 6*r^2 + 1 sqrt(10) B=Jd%Av
% 4 2 4*r^4 - 3*r^2 sqrt(10) RH'F<!p
% 4 4 r^4 sqrt(10) /w xxcq
% 5 1 10*r^5 - 12*r^3 + 3*r sqrt(12) c"sw@<HG
% 5 3 5*r^5 - 4*r^3 sqrt(12) Ff#N|L'9_
% 5 5 r^5 sqrt(12) milK3+N
% --------------------------------------------- jf)JPa_
% 7quwc'!
% Example: +zdq+<9X
% -ZoOX"N}
% % Display three example Zernike radial polynomials J>|:T
% r = 0:0.01:1; ={i&F
% n = [3 2 5]; bd 1J#V]
% m = [1 2 1]; `SS~=~WY
% z = zernpol(n,m,r); by
y1MgQd
% figure 2,e|,N"zN
% plot(r,z) 2|NyAtPb5
% grid on \=G
Xe.}4d
% legend('Z_3^1(r)','Z_2^2(r)','Z_5^1(r)','Location','NorthWest') MdoWqpC
% eg~^wi
% See also ZERNFUN, ZERNFUN2. ]zMBZs
JK8@J9(#
% A note on the algorithm. MVL }[ J
% ------------------------ 3]]6z K^i
% The radial Zernike polynomials are computed using the series UCj#t!Mw
% representation shown in the Help section above. For many special \utH*;J|x
% functions, direct evaluation using the series representation can k#r7&Y
% produce poor numerical results (floating point errors), because p*&LEjaVM4
% the summation often involves computing small differences between 3{LvKe
% large successive terms in the series. (In such cases, the functions /G{3p&9
% are often evaluated using alternative methods such as recurrence [Z Gj7
% relations: see the Legendre functions, for example). For the Zernike x2&