2.1 Dirichlet境界値問題

$\displaystyle -u''(x)=f(x)$   ( $ x\in (0,L)$ )$\displaystyle ,\quad u(0)=u(L)=0
$

$\displaystyle h=\frac{L}{N},\quad x_i=ih$   ( $ i=0,1,\cdots,N$ )$\displaystyle .
$

$\displaystyle \frac{1}{h^2}
\begin{pmatrix}
2 & -1 \\
-1 & 2 & -1 \\
& -1...
...begin{pmatrix}
f(x_1) \\
f(x_2) \\
\vdots \\
f(x_{N-1})
\end{pmatrix}.
$

laplacian1d.m

% -(d/dx)^2 の差分近似
function a=laplacian1d(m)
  e=ones(m,1);
  a=spdiags([-e 2*e -e],-1:1,m,m); % 疎行列なので圧縮した形式
end

>> a=laplacian1d(3));
>> full(a)

ans =
     2    -1     0
    -1     2    -1
     0    -1     2

$ I=(0,L)$ $ N$ 等分する差分近似の場合は
>> L=1;
>> n=5;
>> h=L/n;
>> a=laplacian1d(n-1)/(h*h);
>> full(a)

ans =

   50.0000  -25.0000         0         0
  -25.0000   50.0000  -25.0000         0
         0  -25.0000   50.0000  -25.0000
         0         0  -25.0000   50.0000

$ I=(0,L)$ における

$\displaystyle -u''(x)=1,\quad u(0)=u(L)=0
$

を解くには ($ f\equiv 1$ とするのは安直だけど)
poisson1d_test1.m

L=1
n=10
h=L/n
x=linspace(0,L,n+1);
a=laplacian1d(n-1)/(h*h);
f=ones(n-1,1);
u=a\f;
u=[0; u; 0];
plot(x,u)
figure(gcf)
とする。

$ f(x)=\sin x$ の場合は
poisson1d_test2.m

L=1
n=10
h=L/n
x=linspace(0,L,n+1);
a=laplacian1d(n-1)/(h*h);
f=sin(x(2:n))';
u=a\f;
u=[0; u; 0];
plot(x,u)
figure(gcf)
とする。

$ f(x)=x(1-x)$ の場合は
poisson1d_test3.m

L=1
n=10
h=L/n
x=linspace(0,L,n+1);
a=laplacian1d(n-1)/(h*h);
f=x.*(1-x);
f=f(2:n)';
u=a\f;
u=[0; u; 0];
plot(x,u)
figure(gcf)
とする。

桂田 祐史
2018-11-02