Home > K25104 > Interpolation > spline_pieces.m

spline_pieces

PURPOSE ^

Calculates the coefficients of the polynomial pieces

SYNOPSIS ^

function [ coeffs ] = spline_pieces( nodes,values, derivs )

DESCRIPTION ^

 Calculates the coefficients of the polynomial pieces 
 which compose a cubic spline on each subinterval
 Input arguments:
   nodes, column vector holding the positions of the nodes
   values, column vector holding function values at the nodes
   derivs, column vector holding derivative values at the nodes
 Output arguments:
   coeffs, array holding the coefficients of the polynomial 
     on each subinterval

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ coeffs ] = spline_pieces( nodes,values, derivs )
0002 % Calculates the coefficients of the polynomial pieces
0003 % which compose a cubic spline on each subinterval
0004 % Input arguments:
0005 %   nodes, column vector holding the positions of the nodes
0006 %   values, column vector holding function values at the nodes
0007 %   derivs, column vector holding derivative values at the nodes
0008 % Output arguments:
0009 %   coeffs, array holding the coefficients of the polynomial
0010 %     on each subinterval
0011 
0012 [n,m]=size(nodes);      % finding the size of nodes
0013 [p,q]=size(values);       % finding the size of values
0014 [k,l]=size(derivs);     % finding the sive of derivs
0015 if m~=1 || q~=1 || l~=1
0016     error('inputs must be column vectors');
0017 elseif n~=p || n~=k
0018     error('input vectors must be the same length');
0019 end
0020 
0021 coeffs=zeros(n-1,4);    % intialise array
0022 
0023 coeffs(:,1)=values(1:n-1);
0024 coeffs(:,2)=derivs(1:n-1);
0025 for j=1:n-1;
0026     coeffs(j,3)=3*(values(j+1)-values(j))/((nodes(j+1)-nodes(j))^2)...
0027         -(2*derivs(j)+derivs(j+1))/(nodes(j+1)-nodes(j));
0028     coeffs(j,4)=2*(values(j)-values(j+1))/((nodes(j+1)-nodes(j))^3)...
0029         +(derivs(j)+derivs(j+1))/((nodes(j+1)-nodes(j))^2);
0030 end
0031 
0032 end
0033

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005