Examplecubicspline - function cubic_spline =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
function cubic_spline = c_spline2(x,y,type,smooth) f %The 'type' determines what type of cubic %spline will be fitted to the data: '1' for a natural spline, '2' %for a parabolic runout spline, and '3' for a cubic runout %spline. % % Enter the number of data points n=input('Enter the exponent n: '); n x=-1/2:1/(n-1):1/2; y=sin(2*pi*x); y %Number of elements in the vector x [m,n] = size(x); [ %Plots Ori %plot(x,y,'*'); xlabel('x'); ylabel('y'); title({['Data Set for y=sin(2*pi*x) with' ,int2str(n),' points']}); t hold on h if (nargin < 4) smooth = 0; end e for i = 1:smooth y1 = y; for i = 2:n-1; y(i)=(y1(i)+y1(i+1))/2; end end e % calculates the distance between x-values c h=diff(x); h % calculates the M finding matrix 'M' c M=diag(ones(n,1))+diag(4*ones(n-1,1),1)+diag(ones(n-2,1),2); M = M(1:n-2,2:n-1); M type = 2; if (type == 2) M(1,1) = 5; M(n-2,n-2) = 5; end e
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
e % generates the solution vector s g s=6./(h(1:(end-1)).^2).*diff(diff(y)); s=s'; s format long f % generates the values for M(2) through M(n-1)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

Examplecubicspline - function cubic_spline =...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online