LoginSignup
1
0

More than 3 years have passed since last update.

乱数行列をPivotGauss消去法で解く際のコード

Last updated at Posted at 2018-03-07

学校の課題を提出したので、コードを記事にして保存しました.
条件:
ax=bを解く.
aは500*500の乱数行列(成分は1~9)
(b-ax)の2ノルムを誤差としてerr1に放り込む.
・言語はJava.
ソース全体

    public static main {
        long t0;
        long time;
        int n =500;
        int m=100;
        double [][]a =new double[n][n];
        double []b =new double[n];
        double []x2 =new double[n];
        double err1 =0.0;
        //err1をだす
        t0 = System.currentTimeMillis();
        for(int s=0;s<m;s++){
            for(int j=0;j<n;j++){
                for(int i=0;i<n;i++){
                    a[i][j]=Math.abs((Math.random()));
                    b[i]  =Math.abs((Math.random()));
                }
            }
            x2 =Calc.pivotGauss(a, b);
            err1 =Calc.vecNorm2(Calc.subVec(b,Calc.matVec(a, x2)));
            System.out.println(err2);
        }
        time = System.currentTimeMillis()-t0;
        System.out.println("\n処理時間:"+time);
    }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0