Cの行列作成プログラム

    2003/09/08 日立製作所 & 早稲田大学 後 保範 ( Ushiro Yasunori )
--------------------------------------------------------------

1. 概要

 実密行列を係数とする連立一次方程式Ax=bをブロックガウス消去法でLU分解し、
LUx=bの数値解を前進後退代入で求める行列作成プログラム。
IDAは行列の種類でIDA=0は非対角行列が全て1で対角が1+SIG(入力値)となる。
IDA=1なら全要素を0.0〜1.0の一様乱数で作成する。
IDBは右辺行列の指定であるが、現在は解xが1.0となるようにbを作成。

2. プログラム

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Global Define
#define ND  2000
extern double  WA[ND][ND], WB[ND] ;
//================================================================C
void DMATB(int N, int IDA, int IDB, double SIG)
//================================================================C
//  Real-Dense Matrix Generator                                   C
//----------------------------------------------------------------C
//    WA,WB are global define                                     C
//    N        I*4, In,  Matrix Order of WA                       C
//    IDA      I*4, In,  Identify of Matrix WA                    C
//                       IDA=0 ; Diag=1+Sig, Nondiag=1            C
//                       IDA=1 ; Randum number                    C
//    IDB      I*4, In,  Identify of right Vector WB              C
//                       IDB=0 ; Set x=1                          C
//    SIG      R*8, In,  Value of Generation                      C
//----------------------------------------------------------------C
//    Written by Yasunori Ushiro ,   2003/09/04                   C
//        ( Waseda University and Hitachi Ltd. )                  C
//      Address is equal to Fortran Version                       C
//================================================================C
{ int    i, j, IRAND;
  double V; 
//  Set Matrix A
  V     = 32767.0 ;
  if(IDA == 1) {
    IRAND = fabs(SIG)*V ;
    srand(IRAND) ;
    for (j=0; j<N; j++) {
      for (i=0; i<N; i++)
       { WA[i][j] = rand()/V ;  }
     } }
  else {  
    for (j=0; j<N; j++) {
      for (i=0; i<N; i++)
       { WA[i][j] = 1.0 ; }
      WA[j][j] = 1.0 + SIG ;
   } }
//  Set Right Vector B
  for (i=0; i<N; i++)
   { WB[i] = 0 ; }
  for (i=0; i<N; i++) {
    for (j=0; j<N; j++)
     { WB[i] = WB[i] + WA[i][j] ; }
  }
 }