octaveで疎行列の連立一次方程式を解く。
octaveは無料で使える行列計算システム。
疎行列のセット
データ:
行列A (matA.mat) (7×7)
3列目は行列の値。それ以外は0.
1 2 4
1 3 3
5 2 5
7 5 2
2 4 2
1 4 10
3 1 1
4 6 8
6 7 1
ベクトルb (vecb.mat) (7×1)
5
3
2
1
12
4
6
疎行列の連立方程式の
solve.m
load matA.mat; load vecb.mat; #row=7;col=7; out1=((matA(:,1))); in1=(matA(:,2)); value=(matA(:,3)); row=max(max(out1),max(in1)); col=row; A=sparse(out1,in1,1,rows=row,cols=col); b=sparse(vecb); x=A\b; xf=full(x); [vecb,full(A*x)] save "x.mat" xf;
octave --silent solve.m
でx.matに解を出力。
http://www.network-theory.co.uk/docs/octave3/octave_214.html