function z = zernpol(n,m,r,nflag) 0CSv10Tg
%ZERNPOL Radial Zernike polynomials of order N and frequency M. ys_`e
% Z = ZERNPOL(N,M,R) returns the radial Zernike polynomials of nEzf.[+9/
% order N and frequency M, evaluated at R. N is a vector of dd2[yKC`
% positive integers (including 0), and M is a vector with the (SSRY 9
% same number of elements as N. Each element k of M must be a +q6ydb,
% positive integer, with possible values M(k) = 0,2,4,...,N(k) fEB7j-t
% for N(k) even, and M(k) = 1,3,5,...,N(k) for N(k) odd. R is yA{W
% a vector of numbers between 0 and 1. The output Z is a matrix y@CHR
% with one column for every (N,M) pair, and one row for every hF2IW{=!
% element in R. w\)|
% A!1;}x
% Z = ZERNPOL(N,M,R,'norm') returns the normalized Zernike poly- zMIT}$L
% nomials. The normalization factor Nnm = sqrt(2*(n+1)) is nRd)++
% chosen so that the integral of (r * [Znm(r)]^2) from r=0 to jYNrD"n
% r=1 is unity. For the non-normalized polynomials, Znm(r=1)=1 No2b"G@
% for all [n,m]. S9HwIH\m
% \OlmF<~
% The radial Zernike polynomials are the radial portion of the :JlP[I
% Zernike functions, which are an orthogonal basis on the unit ,C3,TkA]
% circle. The series representation of the radial Zernike 04r$>#E
% polynomials is ;?C#IU
% RN=` -*E1
% (n-m)/2 \uss Uv
% __ %s19KGpA
% m \ s n-2s 8[6o (
% Z(r) = /__ (-1) [(n-s)!/(s!((n-m)/2-s)!((n+m)/2-s)!)] * r @p\}p Y$T
% n s=0 Dk48@`l2
% h6dPO"
% The following table shows the first 12 polynomials. Vh>Z,()>>@
% bLt.O(T}
% n m Zernike polynomial Normalization m N8pg4
% --------------------------------------------- 26CS6(sn
% 0 0 1 sqrt(2) 6q
2_WX
% 1 1 r 2 -G6U$
% 2 0 2*r^2 - 1 sqrt(6) \"hJCP?,
% 2 2 r^2 sqrt(6) ;c$ J=h]
% 3 1 3*r^3 - 2*r sqrt(8) {v3P9s(
% 3 3 r^3 sqrt(8) e%W$*f
% 4 0 6*r^4 - 6*r^2 + 1 sqrt(10) QeF3qXI
% 4 2 4*r^4 - 3*r^2 sqrt(10) yA47"R
% 4 4 r^4 sqrt(10) YKQr,
Now
% 5 1 10*r^5 - 12*r^3 + 3*r sqrt(12) U*.0XNKp{
% 5 3 5*r^5 - 4*r^3 sqrt(12) X$/2[o#g
% 5 5 r^5 sqrt(12) EJ2yO@5O
% --------------------------------------------- #Fyuf,hw4
% cX3l t5
% Example: W`^@)|9^)
% v%Wx4v@%SE
% % Display three example Zernike radial polynomials sVex
(X
% r = 0:0.01:1; (XoH,K?{z
% n = [3 2 5]; y(K"
-?
% m = [1 2 1]; (h:Rh
% z = zernpol(n,m,r); >LDhU%bH
% figure V')0 Mr
% plot(r,z) R:B^
% grid on \l~*PG2
% legend('Z_3^1(r)','Z_2^2(r)','Z_5^1(r)','Location','NorthWest') 1^gl}^|B
% Bj7gQ%>H4
% See also ZERNFUN, ZERNFUN2. T
Q,?>6n
@IXsy
% A note on the algorithm. v$^Z6>vVI
% ------------------------ y!xE<S&Y
% The radial Zernike polynomials are computed using the series U(x]O/m
% representation shown in the Help section above. For many special 4>J
% functions, direct evaluation using the series representation can ;| 1$Q!4
% produce poor numerical results (floating point errors), because NVRLrJWpp
% the summation often involves computing small differences between "Wx]RN:
% large successive terms in the series. (In such cases, the functions 3do)Vg4
% are often evaluated using alternative methods such as recurrence Ha)ANAD
% relations: see the Legendre functions, for example). For the Zernike TsTPj8GAl[
% polynomials, however, this problem does not arise, because the bV"G~3COy
% polynomials are evaluated over the finite domain r = (0,1), and o=1X^,
% because the coefficients for a given polynomial are generally all fDSv?crv
% of similar magnitude. Z@r.pRr'
% =9T$Gr
% ZERNPOL has been written using a vectorized implementation: multiple uG<}N=
% Zernike polynomials can be computed (i.e., multiple sets of [N,M] f7}*X|_Y
% values can be passed as inputs) for a vector of points R. To achieve M9f35
:
% this vectorization most efficiently, the algorithm in ZERNPOL {AQ=<RDRF
% involves pre-determining all the powers p of R that are required to dUsxvho
% compute the outputs, and then compiling the {R^p} into a single Rn@#d}
% matrix. This avoids any redundant computation of the R^p, and "^Ybs'-
% minimizes the sizes of certain intermediate variables. g&{9VK6.
% <