⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weight.m

📁 计算水声传播的快速场(FFP)程序
💻 M
字号:
function [ w, Ix ] = weight( x, xTab )

% Computes weights for linear interpolation
%     Given 
%        x(*)    abscissas
%        xTab(*) points for tabulation
%
%     Compute
%        w(*)    weights for linear interpolation
%        Ix(*)   indices for    "         "
%
% routine can fail if x is not strictly monotonically increasing

% pre-allocate output vectors for efficiency
Nx    = length( x    );
NxTab = length( xTab );
Ix    = zeros( NxTab, 1 );
w     = zeros( NxTab, 1 );

% Quick return if just one X value for interpolation ***

if ( Nx == 1 )
    w(  1 ) = 0.0;
    Ix( 1 ) = 1;
    return
end

L = 1;

for IxTab = 1 : NxTab   % Loop over each point for which the weights are needed
    
    % search for index, L, such that [X(L), X(L+1)] brackets rcvr depth
    while ( xTab( IxTab ) > x( L + 1 ) && L < Nx - 1 )
        L = L + 1;
    end
    Ix( IxTab ) = L;                                                    % here's the output index
    w(  IxTab ) = ( xTab( IxTab ) - x( L ) ) / ( x( L+1 ) - x( L ) );   % here's the output weight
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -