function [a,b,c,d,sp]=nma_spline(x,y) % computes the cubic splines between any number of points. %function [a,b,c,d]=nma_spline(x,y) % % computes the cubic splines between any number of points. % a x^3 + b x^2 + c x + d % % INPUT: % x: an array of the x-coordinates of the points. % y: an array of the y-coordinates of the points. % % OUTPUT: % a: an array of the 'a' coefficients of the splines. % b: an array of the 'a' coefficients of the splines. % c: an array of the 'a' coefficients of the splines. % d: an array of the 'a' coefficients of the splines. % sp: a cell array. each cell contains a string that % represents a spline. % % EXAMPLE: % % x =[ 1 2 3]; % y =[ 3 4 5]; % [a,b,c,d,sp]=nma_spline(x,y); % sp{1} % ans = % +0.000000*(x-1.000000)^3 +0.000000*(x-1.000000)^2 +1.000000*(x-1.000000) +3.000000 % copyright: Nasser M. Abbasi n=length(x); interval = zeros(n-1,1); for i=1:n-1 interval(i)=x(i+1)-x(i); end j=0; C = zeros(n-2,1); for i=2:n-1 j=j+1; C(j)=6*( (y(i+1)-y(i))/interval(i)- (y(i)-y(i-1))/interval(i-1)); end j=0; A=zeros(n-2,n-2); for i=2:n-1 j=j+1; A(j,j)=2*( interval(j) + interval(j+1) ); if(i