DERIV 4th, 6th, 8th and 10th derivatives of the kernel function. CALL: [y4,y6,y8,y10] = deriv(t,kernel) kernel = 'gaussian' - Gaussian kernel (Currently the only supported kernel) DERIV(T,K) finds the derivatives of the kernel K at the point T. Example: [y4,y6,y8,y10]=deriv(0:3);
Display message and abort function. | |
Convert string to lowercase. | |
Differentiate polynomial. | |
Trim polynomial by stripping off leading zeros. | |
Evaluate polynomial. |
L-stage Direct Plug-In estimate of smoothing parameter. | |
Smoothed cross-validation estimate of smoothing parameter. | |
2-Stage Solve the Equation estimate of smoothing parameter. |
001 function [varargout]=deriv(t,k) 002 %DERIV 4th, 6th, 8th and 10th derivatives of the kernel function. 003 % 004 % CALL: [y4,y6,y8,y10] = deriv(t,kernel) 005 % 006 % kernel = 'gaussian' - Gaussian kernel (Currently the only 007 % supported kernel) 008 % 009 % DERIV(T,K) finds the derivatives of the kernel K 010 % at the point T. 011 % 012 % Example: [y4,y6,y8,y10]=deriv(0:3); 013 014 %tested on: matlab 5.3 015 %History 016 %revised pab Aug2005 017 % made it general for derivatives of any order 018 %revised pab dec2003 019 % added todo 020 %revised pab 16.10.1999 021 % updated to matlab 5.x + documentation 022 % by Christian C. Beardah 1995 023 024 025 % TODO % Add support for other kernels than the Gaussian 026 027 if nargin<2|isempty(k) 028 k='gauss'; 029 end 030 031 switch lower(k(1:4)) 032 case {'gaus'}, 033 phi0 = exp(-0.5*t.^2)/sqrt(2*pi); 034 if 1 035 % New call by pab Aug 2005 036 p4 = [1 0 -6 0 +3]; 037 varargout{1} = polyval(p4,t).*phi0; 038 039 pn = p4; 040 for ix = 2:nargout 041 pnp1 = polyadd([-pn,0],polyder(pn)); 042 pnp2 = polyadd([-pnp1,0],polyder(pnp1)); 043 varargout{ix} = polyval(pnp2,t).*phi0; 044 pn = pnp2; 045 end 046 047 else % old call kept just in case 048 y4=(t.^4-6*t.^2+3).*phi0; 049 if nargout>1, 050 y6=(t.^6-15*t.^4+45*t.^2-15).*phi0; 051 end 052 if nargout>2; 053 y8=(t.^8-28*t.^6+210*t.^4-420*t.^2+105).*phi0; 054 end; 055 if nargout>3, 056 y10=(t.^10-45*t.^8+630*t.^6-3150*t.^4+4725*t.^2-945).*phi0; 057 end; 058 end 059 otherwise, 060 disp('Kernel not suported') 061 y4=[];y6=[];y8=[];y10=[]; 062 end; 063 064 065 066 function r = polyadd(p, q) 067 %POLYADD Add polynomials. 068 % 069 % R = POLYADD(P, Q) adds the polynomials whose coefficients are the 070 % elements of the vectors P and Q. 071 % 072 % See also POLYADD, POLYSUB, POLYMUL, POLYDIV, POLYPOW. 073 074 % Author: Peter J. Acklam 075 % Time-stamp: 1998-06-22 20:36:21 076 % E-mail: jacklam@math.uio.no 077 % WWW URL: http://www.math.uio.no/~jacklam 078 079 error(nargchk(2, 2, nargin)); 080 081 m = length(p); 082 n = length(q); 083 l = max(m, n); 084 085 r = zeros(1, l); % Initialize output. 086 r(l-m+1:l) = p; % Insert first polynomial. 087 r(l-n+1:l) = r(l-n+1:l) + q; % Add second polynomial 088 089 r = polytrim(r); % Trim the result.
Comments or corrections to the WAFO group