{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


cubic_spline_evaluate - m=length(x n=length(xx y=x for...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function y = cubic_spline_evaluate (x,S,xx) %% usage: y = spline_evaluate (x,S,xx) %% evaluate the natural cubic spline %% input %% S contains the spline coefficients returned from %% cubic_spline_get_coefficients %% %% xx is the vector containing the x-coordinates of the knots %% it is assumed that these values are in ascending order %% x is the vector of points where the spline is to be evaluated %% output %% y is the vector of y-values that go with the x-values
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: m=length(x); n=length(xx); y=x; for j=1:m %% lookup x(j) %% find integer k such that xx(k) <= x(j) <= xx(k+1) if (x(j) < xx(2)) k=1;u=2; elseif (x(j) > xx(n-1)) k=n-1;u=n; else k=1; u=n; while ((u-k) > 1) %% start bisection search algorithm mp=floor((u+k)*0.5); if( x(j) > xx(mp)) k=mp; else u=mp; end end end %% evaluate the cubic in nested form w=x(j)-xx(k); y(j)=((S(k,1)*w + S(k,2))*w+S(k,3))*w+S(k,4); end;...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online