%Compute XX points possion1D equation
%Use S = 0 as the boundary condition for two external nodes of the gird
%command is 'XX=101'eg.101 points possion1D equation
function [FindSolution_function]=Possion1D_equation(XX)
%sparse matrixs of coefficients_L and right side hands_R
L = sparse(XX,XX);
L1 = full(L);
R = sparse(XX,1);
R1 = full(R);
%found coordinate_x
x = 0:10:(XX-1)*10%1行 101列z = size(x);x1 = x(1,1);x2 = x(1,2);x101 = x(1,101);
%found right hand side R1
for i = 1:1:XX
if i==1
R1(i,1) = 0;
elseif i==XX
R1(i,1) = 0;
else
R1(i,1) = 1;
end
end
%found coefficient L1
L1(1,1) = 1;
L1(XX,XX) = 1;
for i=1:1:XX
%first line = 0 except fai1 = 1
if abs(i)>=2
L1(1,i) = 0;
end
%last line = 0 except fai101 = 1
if abs(i)<=XX-1
L1(XX,i) = 0;
end
%from second line to one hundred line
if abs(i)>=2 & abs(i)<=XX-1
L1(i,i-1) = 2./(x(1,i)-x(1,i-1))./(x(1,i+1)-x(1,i-1));
L1(i,i) = (-2./(x(1,i)-x(1,i-1))-2./(x(1,i+1)-x(1,i)))./(x(1,i+1)-x(1,i-1));
L1(i,i+1) = 2./(x(1,i+1)-x(1,i))./(x(1,i+1)-x(1,i-1));
end
end
%compute S:S1 = L1\R1
S1 = L1\R1
%visualize result of unknowns
i = 0:1:XX-1
plot(i,S1,'k','LineWidth',3)
title('Result of XX points possion equatioin');
xlabel('Points')
ylabel('value of unknowns')