
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

function [s] = generate_spline(n,x,a) % STEP 1: for i=1:n- h(i)=x(i+1)-x(i); end % STEP 2: for i=2:n- alpha(i)=(3/h(i))(a(i+1)-a(i))-(3/h(i-1))(a(i)-a(i-1)); end % STEP 3: l(1)=1; u(1)=0; z(1)=0; % STEP 4: for i=2:n-1; l(i)=2(x(i+1)-x(i-1))-h(i-1)u(i-1); u(i)=h(i)/l(i); z(i)=(alpha(i)-h(i-1)z(i-1))/l(i); end % STEP 5: l(n)=1; z(n)=0; c(n)=0; % STEP 6: for j=n-1:-1:1; c(j)=z(j)-u(j)c(j+1); b(j)=(a(j+1)-a(j))/h(j)-h(j)(c(j+1)+2c(j))/3; d(j)=(c(j+1)-c(j))/(3h(j)); end % STEP 7: s = []; for i=1:(n-1) xx = x(i):0.001:(x(i+1)-0.001); s = [s a(i)+b(i)(xx-x(i))+c(i)(xx-x(i)).^2+d(i)(xx-x(i)).^3]; end % Step 7: s = []; for i=1:n- xx = x(i):0.001:(x(i+1)-0.001); s = [s a(i)+b(i)(xx-x(i))+c(i)(xx-x(i)).^2+d(i)*(xx-x(i)).^3]; end