%demo2 solves u"=x, u(0)=0, u(1)=1
N=4;
dx=1/(N-1);
ex2=inline('x.^3/6+5*x/6','x');
x=0:dx:1;
Dx=diff(x');
u=0*x';u(N)=1;
A=diag(-2*ones(N-2,1),0)+diag(ones(N-3,1),1)+diag(ones(N-3,1),-1);
b=-u(3:end);b=b+dx^2*x(2:N-1)';%Dx(1:end-1).^2;
u(2:N-1)=A\b;
xf=0:.01:1;
% plot(x,u,'k-o',xf,ex2(xf),'r-','markerfacecolor','k')
% xlabel('x');ylabel(' u(x)')
% title(' FD solution with zero forcing ')
% legend(' Numerical ',' Exact ',4)

subplot(2,1,1),plot(x,u,'k-o','markerfacecolor','k')
xlabel('x');ylabel(' u(x)')
title(' FD solution with zero forcing ')
legend(' Numerical ',4)
subplot(2,1,2),plot(xf,ex2(xf),'r-','markerfacecolor','k')
xlabel('x');ylabel(' u(x)')
title(' FD solution with zero forcing ')
legend(' Exact ',4)