clear all
clear all;
Delta=0.2;
x=1:Delta:2;
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)=-(2/Delta.^2)-2./(x(2).^2);
A(1,2)=(1/Delta.^2)+(2./x(2))*(1/(2*Delta));
for i=2:n-2
A(i,i-1)=(1/Delta.^2)-(2./x(i+1))*(1/(2*Delta));
A(i,i)=-(2/Delta.^2)-2./(x(i+1).^2);
A(i,i+1)=(1/Delta.^2)+(2./x(i+1))*(1/(2*Delta));
end
A(n-1,n-2)=(1/Delta.^2)-(2./x(n))*(1/(2*Delta));
A(n-1,n-1)=-(2/Delta.^2)-2./(x(n).^2);
C(1)=-alpha*((1/Delta.^2)-(2./x(2))*(1/(2*Delta)));
C(n-1)=-beta*((1/Delta.^2)+(2./x(n))*(1/(2*Delta)));
%
% 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)=alpha;
ysol(2:n)=yinner;
ysol(n+1)=beta;
hold off;
plot(x,ysol,’bo-‘,’Markersize’,15,’Markerfacecolor’,[0 0 1]);
hold on
plot(x,x+4./x.^2,’k-‘,’linewidth’,2);
xlabel(‘x’,’FontSize’,14)
ylabel(‘y(x)’,’FontSize’,14)