MATLAB の実行例 (1) すべて対話的に実行


>> n=5

n =

     5

>> J=diag(ones(n-1,1),1)+diag(ones(n-1,1),-1)

J =

     0     1     0     0     0
     1     0     1     0     0
     0     1     0     1     0
     0     0     1     0     1
     0     0     0     1     0

>> Ap=4*eye(n,n)-J

Ap =

     4    -1     0     0     0
    -1     4    -1     0     0
     0    -1     4    -1     0
     0     0    -1     4    -1
     0     0     0    -1     4

>> n2=2*n

n2 =

    10

>> Ac=zeros(n2,n2)

Ac =

     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

>> Ac(1:n,1:n)=Ap

Ac =

     4    -1     0     0     0     0     0     0     0     0
    -1     4    -1     0     0     0     0     0     0     0
     0    -1     4    -1     0     0     0     0     0     0
     0     0    -1     4    -1     0     0     0     0     0
     0     0     0    -1     4     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

>> c=1

c =

     1

>>  Ac(n+1:n2,n+1:n2)=c*Ap

Ac =

     4    -1     0     0     0     0     0     0     0     0
    -1     4    -1     0     0     0     0     0     0     0
     0    -1     4    -1     0     0     0     0     0     0
     0     0    -1     4    -1     0     0     0     0     0
     0     0     0    -1     4     0     0     0     0     0
     0     0     0     0     0     4    -1     0     0     0
     0     0     0     0     0    -1     4    -1     0     0
     0     0     0     0     0     0    -1     4    -1     0
     0     0     0     0     0     0     0    -1     4    -1
     0     0     0     0     0     0     0     0    -1     4

>> lambda=eig(Ac)

lambda =

    2.2679
    2.2679
    3.0000
    3.0000
    4.0000
    4.0000
    5.0000
    5.0000
    5.7321
    5.7321

>> plot(1:n2,lambda)
>> 

図 1: $ c=1$ の場合の $ A_c$ の固有値の分布
\includegraphics[width=10cm]{eps/cg-eigen1.eps}

桂田 祐史
2017-06-19