% spline_fun.m % % This code originally used in MA 530 at NCSU. % % % start with a clean slate clear clg axis ([0 10 0 10]) hold on % Initially, the list of points is empty x = [ ]; y = [ ]; n = 0; % Loop, picking up the points, disp('Left mouse button picks points.') disp('Right mouse button picks last point.') but =1; while but ==1 [xi,yi,but] = ginput(1); plot(xi,yi,'go') n = n+1; x(n,1) = xi; y(n,1) = yi; end % Construct x_fine for i=1:length(x)-1 x_fine(:,i) = [x(i,1):(x(i+1,1)-x(i,1))/99:x(i+1,1)]'; end % Construct the cubic spline ys = spline(x, y, x_fine); % Plot the interpolated curve hp = plot(x', y', 'o',x_fine,ys); xlabel('x');ylabel('u'); legend(hp,'Data Points','Cubic Spline'); title('Well Chosen Example of Data Points and Cubic Spline'); hold off