Why in collocation method if $h$ more smaller, the result is bad?

I want to solve BVP numerically $$$$y''+4y'+13y=e^{-2x}, \text{ } 0\leq x\leq 2$$$$ with $$$$\label{konba1} y(0)=\dfrac{10}{9}$$$$ and $$$$\label{konba2} y(2)=e^{-4}\left(\sin(6)+\cos(6)+\dfrac{1}{9}\right).$$$$ using collocation method. Assuming the solution is $$$$\label{meong} y=\sum\limits_{i=0}^n c_i x^i,$$$$ we get system of linear equation

$$\begin{eqnarray*} \left[ \begin{matrix} 1&0&0\\ 13&4+13x_1&2+8x_1+13{x_1}^2\\ \vdots&\vdots&\vdots\\ 13&4+13x_{n-1}&2+8x_{n-1}+13{x_{n-1}}^2\\ 1&2&4 \end{matrix} \right. \left. \begin{matrix} \ldots&0\\ \ldots&n(n-1) {x_1}^{n-2}+4n {x_1}^{n-1}+13{x_1}^n\\ \ddots&\vdots\\ \ldots&n(n-1) {x_{n-1}}^{n-2}+4 n {x_{n-1}}^{n-1}+13 {x_{n-1}}^n\\ \ldots&2^n\\ \end{matrix} \right]\\ \begin{bmatrix} c_0\\c_1\\\vdots\\c_{n-1}\\c_n \end{bmatrix} = \begin{bmatrix} \dfrac{10}{9}\\e^{-2{x_1}}\\\vdots\\e^{-2x_{n-1}}\\e^{-4}\left(\sin(6)+\cos(6)+\dfrac{1}{9}\right) \end{bmatrix}. \end{eqnarray*}$$ The matrix is derived like in this reference https://www.slideshare.net/SuddhasheelGhosh/point-collocation-method-used-in-the-solving-of-differential-equations-particularly-in-finite-element-methods

I solve it using matlab with this code

clear all;
clc;
h=0.1;
x=0:h:2;
n=length(x);
fprintf('METODE KOLOKASI\n===============\n');
for i=1:n
for j=1:n
if i==1&&j==1
A(i,j)=1;
elseif i==1&&j~=1
A(i,j)=0;
elseif i==n
A(i,j)=2^(j-1);
else
A(i,j)=(j-1)*(j-2)*x(i)^(j-3)+4*(j-1)*x(i)^(j-2)+13*x(i)^(j-1);
end
end
end
for i=1:n
if i==1
B(i)=10/9;
elseif i==n
B(i)=exp(-4)*(sin(6)+cos(6)+1/9);
else
B(i)=exp(-2*x(i));
end
end
B=B';
koef=inv(A)*B;
fprintf('  i        ti   y num_i    yeks_i     error\n');
for i=1:n
ynum(i)=0;
for in=1:n
ynum(i)=ynum(i)+koef(in)*x(i)^(in-1);
end
yeks(i)=exp(-2*x(i))*(cos(3*x(i))+sin(3*x(i))+1/9);
error(i)=abs(ynum(i)-yeks(i));
fprintf('%3d%10.4f%10.5f%10.5f%10.5f\n',i,x(i),ynum(i),yeks(i),error(i));
end
figure(1);
plot(x,ynum,'p','markersize',10,'color','b','markerfacecolor','g');
grid on;
axis equal;
hold on;
plot(x,yeks,'-','color','k','linewidth',1.5);
title(sprintf('Solusi Numerik dan Solusi Eksak Metode Kolokasi untuk h=%.3f',h));
xlabel('x');
ylabel('y');
legend('Solusi Numerik','Solusi Eksak');
figure(2);
plot(x,error,'r-');
grid on;
title(sprintf('Error for h=%.3f',h));


For $$h=0.1$$, I get

And for $$h=0.01$$, I get

The matlab output is showing

Warning: Matrix is close to singular or badly
scaled. Results may be inaccurate. RCOND =
8.316723e-75.


Why if we make $$h$$ smaller, then the solution of $$y(2)$$ is not satisfy the boundary condition? And how to make the numerical solution is satisfy the boundary condition?

• It is not so much that the step size gets smaller than that the degree gets higher, see the Runge phenomenon for polynomial approximation. The condition number of the matrix increases, giving less and less accurate solutions. Polynomial evaluation also gets in general less and less accurate at higher degrees, see the Wilkinson polynomial. What you can do is fix a relatively low degree and make a subdivision where you compute approximation polynomials for each sub-interval. – LutzL May 8 at 6:43
• I have tried to compute the approximation polynomial of third degree of each subdivision(which contain 3 subintervals), with step size $h=1/3$ i.e. for first subdivision (we compute polynomial which through $x(1)=0$, $x(2)=1/3$, $x(3)=2/3$, and $x(4)=1$). I cannot find the polinomial approximation because I don't have the solution for $y(x=1)$. I only have the solution $y(x=0)$ and $y(x=2)$ from boundary conditions. So how to find the approximation polynomial? – Ongky Denny Wijaya May 9 at 5:49
• You get a polynomial $p_1$ for $[0,1]$ and $p_2$ for $[1,2]$ and the connecting condition is $p_1(1)=p_2(1)$. You still need to solve the full system at once. You can of course also partition the solution process and reduce the defect in that connecting equation in an outer loop, but usually such partitioned solvers, cycling over subspaces, converge slower. – LutzL May 9 at 6:39
• What do you mean about "need to solve the full system at once"? Is it same with my question above? – Ongky Denny Wijaya May 9 at 7:12
• Spline approximations are usually much better conditioned than high-degree polynomial approximations. The coefficients are still coupled over the full interval, even if the matrix is now banded, or concentrated close to the diagonal. – LutzL May 9 at 7:18