csplineeval.m

来自「Interpolation routines in matlab」· M 代码 · 共 56 行

M
56
字号
%% Evaluate the cubic spline which on [ x(i) , x(i+1) ] is defined by%%    S(z) = a(i) + b(i)*(z-x(i)) + c(i)*(z-x(i))^2 + d(i)*(z-x(i))^3%% at given points z%% function [s] = csplineeval( x, a, b, c, d, z )%% input:%        x:     vector containing the %               interpolation points%%        a:     vector containing the %               coefficients a(i)%%        b:     vector containing the %               coefficients b(i)%%        c:     vector containing the %               coefficients c(i)%%        d:     vector containing the %               coefficients d(i)%%        z:     vector containing the %               points at which the spline has to evaluated%% output:%        s:    value of the spline at the points z%              if z(i) is not contained in the interval [ x(1), x(n) ],%              then s(i) is set to NaN.%%function [s] = csplineeval( x, a, b, c, d, z );n = size(x(:),1);m = size(z(:),1);for i = 1:m   if( z(i) >= x(1) & z(i) <= x(n) )        j = 1;       while  z(i) > x(j+1)            j = j+1;       end       t    = z(i) - x(j);       s(i) = ((d(j)*t+c(j))*t+b(j))*t+a(j);   else       s(i) = NaN;   endend

⌨️ 快捷键说明

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