Home > functions > leadfield > spherical_harmo > vb_legendre_basis.m

vb_legendre_basis

PURPOSE ^

Calculate Legendre basis function (Normalized)

SYNOPSIS ^

function [P ,Itbl, Dim] = vb_legendre_basis( z, N ,mode)

DESCRIPTION ^

 Calculate Legendre basis function (Normalized)
 [usage]
   [P ,Itbl, Dim] = vb_legendre_basis( z, N )
 [input]
   z : (NP x 1) normalized z-coordinates of NP points
   N : maximum order of Legendre function
 mode : normalization mode , 
      = 'norm' : normalized (default), '' : unnormalized
 [output]
   P    : Legendre basis function 
  Itbl  : Index table to map (n,m) to 'k' of P(:,k)
  Dim   : Degree of Legendre function

 --- Example to get Legendre(z ,n, m)
 k = Itbl(n+1,m+1)        for ( n = 0:N ; m = 0:N )
 
 P(:,k) = Legendre(z ,n, m) for ( n = 0:N ; m = 0:n )
  if m > n, k = Itbl(n+1,m+1) = 0, which means P(:,k) = 0

 P(:,1) = Legendre(z ,n=0 ,m=0 ) = 1 
 P(:,2) = Legendre(z ,n=1 ,m=0 )
 P(:,3) = Legendre(z ,n=1 ,m=1 )
     ...
 P(:,D) = Legendre(z ,n=N ,m=N )
     D  = (N+1) * (N+2)/2 

 Dim(1,k) = n : degree of legendre function
 Dim(2,k) = m : degree of azimuthal angle rotation

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [P ,Itbl, Dim] = vb_legendre_basis( z, N ,mode)
0002 % Calculate Legendre basis function (Normalized)
0003 % [usage]
0004 %   [P ,Itbl, Dim] = vb_legendre_basis( z, N )
0005 % [input]
0006 %   z : (NP x 1) normalized z-coordinates of NP points
0007 %   N : maximum order of Legendre function
0008 % mode : normalization mode ,
0009 %      = 'norm' : normalized (default), '' : unnormalized
0010 % [output]
0011 %   P    : Legendre basis function
0012 %  Itbl  : Index table to map (n,m) to 'k' of P(:,k)
0013 %  Dim   : Degree of Legendre function
0014 %
0015 % --- Example to get Legendre(z ,n, m)
0016 % k = Itbl(n+1,m+1)        for ( n = 0:N ; m = 0:N )
0017 %
0018 % P(:,k) = Legendre(z ,n, m) for ( n = 0:N ; m = 0:n )
0019 %  if m > n, k = Itbl(n+1,m+1) = 0, which means P(:,k) = 0
0020 %
0021 % P(:,1) = Legendre(z ,n=0 ,m=0 ) = 1
0022 % P(:,2) = Legendre(z ,n=1 ,m=0 )
0023 % P(:,3) = Legendre(z ,n=1 ,m=1 )
0024 %     ...
0025 % P(:,D) = Legendre(z ,n=N ,m=N )
0026 %     D  = (N+1) * (N+2)/2
0027 %
0028 % Dim(1,k) = n : degree of legendre function
0029 % Dim(2,k) = m : degree of azimuthal angle rotation
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 if ~exist('N','var'), N=10; end;
0035 if ~exist('mode','var'), mode = 'norm'; end;
0036 
0037 NP = length(z);
0038 
0039 % number of legendre basis function
0040 D  = (N+1) * (N+2)/2 ;
0041 P  = zeros(NP,D);
0042 
0043 Dim  = zeros(2,D);
0044 Itbl = zeros(N+1,N+1);
0045 
0046 % Legendre(z ,n=0 ,m=0 ) = 1
0047 Itbl(1,1) = 1;
0048 P(:,1)    = 1;
0049 
0050 i_st = 2;
0051 
0052 for n = 1:N
0053     % Legendre(z ,n, m) : n次ルジャンドル関数
0054     % i_st  : Start index for n-th Legendre function
0055     % i_end :   End index for n-th Legendre function
0056 
0057     i_end = i_st + n;
0058     
0059     % Make index table
0060     Dim( 1, i_st:i_end) = n;
0061     Dim( 2, i_st:i_end) = 0:n;
0062     Itbl( n+1, 1:n+1)   = i_st:i_end;
0063     
0064     % Legendre( z, n, m = 0:n )
0065     switch    mode
0066     case    ''
0067         P(:,i_st:i_end) = legendre(n,z)'; 
0068     case    'norm'
0069         P(:,i_st:i_end) = legendre(n,z,'norm')'; 
0070     end
0071     
0072     i_st = i_end+1;
0073 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005