function z = zernpol(n,m,r,nflag) $r.U
%ZERNPOL Radial Zernike polynomials of order N and frequency M. ReB7vpd
% Z = ZERNPOL(N,M,R) returns the radial Zernike polynomials of RNJFSD.
% order N and frequency M, evaluated at R. N is a vector of 3 pWM~(#>-
% positive integers (including 0), and M is a vector with the }U5Y=RYo
% same number of elements as N. Each element k of M must be a 5a`%)K
% positive integer, with possible values M(k) = 0,2,4,...,N(k) dz9Y}\2tf
% for N(k) even, and M(k) = 1,3,5,...,N(k) for N(k) odd. R is Qc-(*}
% a vector of numbers between 0 and 1. The output Z is a matrix [uuj?Rbd
% with one column for every (N,M) pair, and one row for every z5cYyx
r>
% element in R. R'K/t|MC
% &V=7D# L
% Z = ZERNPOL(N,M,R,'norm') returns the normalized Zernike poly- bi[7!VQf
% nomials. The normalization factor Nnm = sqrt(2*(n+1)) is <>&=n+i
% chosen so that the integral of (r * [Znm(r)]^2) from r=0 to ;<Qdy`
T
% r=1 is unity. For the non-normalized polynomials, Znm(r=1)=1 D#rrW?-z
% for all [n,m]. <lwuTow
% GlYly5F
% The radial Zernike polynomials are the radial portion of the j+ ::y) $
% Zernike functions, which are an orthogonal basis on the unit pK_?}~
% circle. The series representation of the radial Zernike _2Py\+$
% polynomials is d.F)9h]XHO
% 'Z!Ga.I
% (n-m)/2 c$M%G)P
% __ }6m?d!m
% m \ s n-2s C0C0GqN,
% Z(r) = /__ (-1) [(n-s)!/(s!((n-m)/2-s)!((n+m)/2-s)!)] * r I*)VZW
% n s=0 >l1r,/\\
% =]>%t]
% The following table shows the first 12 polynomials. }p3b#fAr
% I<\
'%
% n m Zernike polynomial Normalization [I+9dSM1t
% --------------------------------------------- Opg#*w%-
% 0 0 1 sqrt(2) D,;\F,p
% 1 1 r 2 dSK0h(8
% 2 0 2*r^2 - 1 sqrt(6) f?UzD#50D
% 2 2 r^2 sqrt(6) j~av\SCU*
% 3 1 3*r^3 - 2*r sqrt(8) F@W*\3)
% 3 3 r^3 sqrt(8) /p`&;/V|
% 4 0 6*r^4 - 6*r^2 + 1 sqrt(10) JSVeU54T^<
% 4 2 4*r^4 - 3*r^2 sqrt(10) /XpSe<3
% 4 4 r^4 sqrt(10) 4MvC]_&
% 5 1 10*r^5 - 12*r^3 + 3*r sqrt(12) MgJ5B(c
% 5 3 5*r^5 - 4*r^3 sqrt(12) ocA]M=3~k
% 5 5 r^5 sqrt(12) Zr/r2
% --------------------------------------------- C8b''9t.
% H#(<-)j0_
% Example: n~r 9!m$<
% )iE"Tl
% % Display three example Zernike radial polynomials
M[P^]J@
% r = 0:0.01:1; !$xu(D.
% n = [3 2 5]; dk5|@?pe
% m = [1 2 1]; 1"E\C/c
% z = zernpol(n,m,r); KFhG (
% figure F8mC?fbK9
% plot(r,z) 8C&x MA^
% grid on KCqqJ}G
% legend('Z_3^1(r)','Z_2^2(r)','Z_5^1(r)','Location','NorthWest') #uvJH8)D
% +<(a}6dt
% See also ZERNFUN, ZERNFUN2. Uene=Q6>
/=T"=bP#/
% A note on the algorithm. 3:`XG2'
% ------------------------ TipHV;|e
% The radial Zernike polynomials are computed using the series (F5ttQPh
% representation shown in the Help section above. For many special sBW3{uK
% functions, direct evaluation using the series representation can -Zy)5NB-tZ
% produce poor numerical results (floating point errors), because JeQ[qQ
% the summation often involves computing small differences between 8 njuDl
% large successive terms in the series. (In such cases, the functions /tKGwX]y
% are often evaluated using alternative methods such as recurrence vA>W9OI
% relations: see the Legendre functions, for example). For the Zernike rw u3Nb
% polynomials, however, this problem does not arise, because the G}Z4g
% polynomials are evaluated over the finite domain r = (0,1), and _wu*M
% because the coefficients for a given polynomial are generally all 3 wt
% of similar magnitude. U ":"geU
% !#}>Hv^N
% ZERNPOL has been written using a vectorized implementation: multiple Q<