t = 0:0.1:1;
a1 = 1;
a2 = 2;
c = 0;

% Berechnung der Steifigkeitsatrix

A = zeros(length(t)-2, length(t)-2);

for i = 1:(length(t)-2)
 
    A(i,i) = -1/(t(i+1)-t(i))-1/(t(i+2)-t(i+1));
    A(i,i) = A(i,i) + (c*(t(i+2)-t(i)))/3;
    
    
end

for i = 1:(length(t)-3)
    
    A(i,i+1) = 1/(t(i+2)-t(i+1));
    A(i,i+1) = A(i,i+1) + (c*(t(i+2)-t(i+1)))/6;
    A(i+1, i) = A(i, i+1);
    
end

%Berechnung des Ladevektors (i)

for i = 1:(length(t)-2)
    
    b(i) = 0.5*(2-c*a1)*(t(i+1)-t(i));
    b(i) = b(i) - (c*(a2-a1)/(t(i+1)-t(i)))*(-0.5*t(i)*t(i+1)^2+(1/3)*t(i+1)^3+(1/6)*t(i)^3);
    b(i) = b(i) + (2-c*a1)*(t(i+2)-t(i+1))-0.5*c*(a2-a1)*(t(i+2)^2-t(i+1)^2);
    b(i) = b(i) - 0.5*(2-c*a1)*(t(i+2)-t(i+1));
    b(i) = b(i) + (c*(a2-a1)/(t(i+2)-t(i+1)))*(-0.5*t(i+1)*t(i+2)^2+(1/3)*t(i+2)^3+(1/6)*t(i+1)^3);
    
end

b = b';

v = A\b;

v = [0;v;0];

for i = 1:length(t)
    
    u(i) = v(i) + (a2-a1)*t(i)+a1;
    
end



plot(t,u);