clc
clear all
close all

%% SPLINE CUBICA NATURAL

x = [0.5:0.05:0.8]'
y = [1.2 1 0.7 0.6 0.1 -0.2 -0.6]'

% CREATE h's
for i = 1:length(x)-1
     h(i) = x(i+1)-x(i);
endfor

% CREATE u's
for i = 2:length(x)-1
     u(i) = 2*(h(i)+h(i-1));
endfor

% CREATE b's
for i = 1:length(x)-1
     b(i) = (y(i+1)-y(i))/h(i);
endfor

% CREATE v's
for i = 2:length(x)-1
     v(i) = 6*(b(i)-b(i-1));
endfor

% CREATE MATRIX A
A = zeros(length(x),length(x));

for i = 1:length(x)
     if (i == 1 || i == length(x))
          A(i,i) = 1;
     else
          A(i,i) = u(i);
          A(i,i-1) = h(i-1);
          A(i,i+1) = h(i);
     end
endfor

vec_ind = [0; v(2:end)' ;0];

z = A\vec_ind



% CREATE INDEPENDENT VECTOR











