clear all

N=15;                                  % Antal inre punkter
h=1/(N+1);                             % Steglängd 

x=[1:h:2]';
g=2-2*x+x.^2;

A=sparse(N,N);


for i=1:N
  A(i,i) = 1-2/h^2;                    % Diagonalen
end
for i=1:N-1
  A(i,i+1) = 1/h^2 -1/(2*h)*g(i+1);    % Överdiagonalen
  A(i+1,i) = 1/h^2+1/(2*h)*g(i+2);     % Underdiagonalen
end

b=zeros(N,1);
b(N) = -(1/h^2-1/(2*h)*g(N+1));        % Högerled 

y=A\b;

yplot=[0;y;1];

figure(1)

plot(x,yplot,'-ro'), hold on
grid on
title('Exs 7.16')
xlabel('x')
ylabel('y')
