function z = zernpol(n,m,r,nflag) 4nfpPNt
%ZERNPOL Radial Zernike polynomials of order N and frequency M. fJb<<6C
% Z = ZERNPOL(N,M,R) returns the radial Zernike polynomials of B|~tW21
% order N and frequency M, evaluated at R. N is a vector of B4yC"55
% positive integers (including 0), and M is a vector with the }CiB+
% same number of elements as N. Each element k of M must be a =-r[ s%t&
% positive integer, with possible values M(k) = 0,2,4,...,N(k) 'n9<z)/,!
% for N(k) even, and M(k) = 1,3,5,...,N(k) for N(k) odd. R is V?a+u7*U&
% a vector of numbers between 0 and 1. The output Z is a matrix GtC bzNY
% with one column for every (N,M) pair, and one row for every YR2Q6}xR
% element in R. [q/tKdo@
% x>?jfN,e
% Z = ZERNPOL(N,M,R,'norm') returns the normalized Zernike poly- y7;i4::A\
% nomials. The normalization factor Nnm = sqrt(2*(n+1)) is H>x(c|ZBp
% chosen so that the integral of (r * [Znm(r)]^2) from r=0 to bvf}r
,`Q7
% r=1 is unity. For the non-normalized polynomials, Znm(r=1)=1 cBl
F
% for all [n,m]. PfaBzi9?f
% SxHj3,`#C
% The radial Zernike polynomials are the radial portion of the GvL)SVv?
% Zernike functions, which are an orthogonal basis on the unit \BV$p2m5-
% circle. The series representation of the radial Zernike NDJIaX:]
% polynomials is #+vIq?
% ]"jJgO^
% (n-m)/2 Ye '=F
% __ oJcDs-!
% m \ s n-2s L8&$o2+07r
% Z(r) = /__ (-1) [(n-s)!/(s!((n-m)/2-s)!((n+m)/2-s)!)] * r l Ikh4T6i
% n s=0 D5wy7`c
% e;y\v/A
% The following table shows the first 12 polynomials. $c!cO" U
% @A_bZQ@
% n m Zernike polynomial Normalization _&Hq`KJm
% --------------------------------------------- %>dCAj"
% 0 0 1 sqrt(2) 3HU_~%l
% 1 1 r 2 na;U]IK
% 2 0 2*r^2 - 1 sqrt(6) %nTgrgS(=
% 2 2 r^2 sqrt(6) %Ts6M,Fpp
% 3 1 3*r^3 - 2*r sqrt(8) R. sRH/6
% 3 3 r^3 sqrt(8) ,cbCt
% 4 0 6*r^4 - 6*r^2 + 1 sqrt(10) `CWI%V
% 4 2 4*r^4 - 3*r^2 sqrt(10) %_rdO(
% 4 4 r^4 sqrt(10) h&$7^P
% 5 1 10*r^5 - 12*r^3 + 3*r sqrt(12) +:hZ,G?>
% 5 3 5*r^5 - 4*r^3 sqrt(12) U>b mCK2
% 5 5 r^5 sqrt(12) j4ARGkK5B
% --------------------------------------------- 8X6F6RK6,1
% (v11;k dJB
% Example: `D0>L'
% XYJ7k7zc+Y
% % Display three example Zernike radial polynomials xWw Qm'I2}
% r = 0:0.01:1; (]JZ1s|
% n = [3 2 5]; Y#>'.$(Az
% m = [1 2 1]; .?L&k|wX-
% z = zernpol(n,m,r); Uxla,CCp-
% figure cs]N%M^s
% plot(r,z) ~uF%*
% grid on ,_STt)
% legend('Z_3^1(r)','Z_2^2(r)','Z_5^1(r)','Location','NorthWest') 'W!N1W@
% T6gugDQ~.
% See also ZERNFUN, ZERNFUN2. Q\pTyNAYn
hJrcy!P<a
% A note on the algorithm.
1o&]=(
% ------------------------ RTPxAp+\5
% The radial Zernike polynomials are computed using the series -dCM
eC
% representation shown in the Help section above. For many special MIblx
% functions, direct evaluation using the series representation can ~]}V"O%,
% produce poor numerical results (floating point errors), because D(EY"s37
% the summation often involves computing small differences between &