clear all
clear all;
Delta=0.01;
x=0:Delta:1;
alpha=5.0;
beta=3.0;
n=length(x)-1;
A=zeros(n-1,n-1);
C=zeros(n-1,1);
ysol=zeros(size(x));
A(1,1)=-(1/Delta.^2);
A(1,2)=(1/Delta.^2);
for i=2:n-2
A(i,i-1)=(1/Delta.^2);
A(i,i)=-(2/Delta.^2);
A(i,i+1)=(1/Delta.^2);
C(i)=1;
end
A(n-1,n-2)=(1/Delta.^2);
A(n-1,n-1)=-(2/Delta.^2);
C(1)=1;
C(n-1)=1-(1./Delta^2);
%
% This is a very inefficient way of solving this system of equations
% Matrix [A] has got lots of zeros
% Should use Thomas algorithm and not store all the zeros.
%
yinner=A\C;
ysol(1)=yinner(1);
ysol(2:n)=yinner;
ysol(n+1)=1;
hold off;
plot(x,ysol,’bo-‘,’Markersize’,15,’Markerfacecolor’,[0 0 1]);
hold on
plot(x,0.5*(x.^2+1),’k-‘,’linewidth’,2);
xlabel(‘x’,’FontSize’,14)
ylabel(‘y(x)’,’FontSize’,14)