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 |
を 等分する差分近似の場合は
>> 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 |
における
を解くには ( とするのは安直だけど)
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) |
の場合は
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) |
の場合は
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) |
桂田 祐史