Esempio n. 1
0
static int ortogonalisoi()
        {
        double eps,tol;
        int i,j;
        int jj;

/*      sur_print("\nOrthogonalizing data...");  */
        eps=1e-16; tol=1e-300/eps;
        mat_tred2(v1,v2,T,m,tol);
        mat_tql2(v1,v2,T,m,eps,30);
        for (j=0; j<m; ++j)
            {
            eps=1/sqrt(v1[j]);
            for (i=0; i<m; ++i) T[i+m*j]*=eps;
            }

        hav=muste_fopen(tempfile,"r+b");
        for (jj=0L; jj<n; ++jj)
            {
            hav_read3(jj,xx);
            mat_mlt(v2,xx,T,1,m,m);
            hav_write3(jj,v2);
            }
        muste_fclose(hav);
        return(1);
        }
Esempio n. 2
0
static int yao_test() // Srivastava s.119
    {
    int i,j,k;
    double a,dn,f,dm;

// Rprintf("\nt2=%g",t2_BF0); getch();
/*******************
printf("\nkeskiarvot:");
mprint(ss[0],1,m);
mprint(ss[1],1,m);
mprint(ss2[0],m,m);
********************/

    for (i=0; i<m; ++i) ero[i]=ss[0][i]-ss[1][i];

    f=0.0;
    for (k=0; k<2; ++k)
        {
        for (i=0; i<m; ++i)
            for (j=0; j<=i; ++j)
                 {
          ss_apu2[i+m*j]=(ss2[k][i+m*j]-n[k+1]*ss[k][i]*ss[k][j])/(double)(n[k+1]-1);
          ss_apu2[j+m*i]=ss_apu2[i+m*j];
                 }
        mat_mlt(ss_apu,ss_inv,ss_apu2,m,m,m);
        mat_mlt(ss_apu2,ss_apu,ss_inv,m,m,m);

        mat_mlt(ss_apu,ss_apu2,ero,m,m,1);

        mat_mlt(ss_apu2,ero,ss_apu,1,m,1);

        dn=(double)n[k+1];
        a=ss_apu2[0];
        a=a*a/(t2_BF0*t2_BF0*dn*dn*(dn-1.0));
        f+=a;

        }
    f=1.0/f;

    dm=(double)m;
    p_yao=1.0-muste_cdf_f((f-dm+1.0)/(f*m)*t2_BF0,
                        dm,f-dm+1.0,1e-15);
// Rprintf("\nf=%g P=%g",f,p_yao); getch();
    return(1);
    }
Esempio n. 3
0
File: nterm.c Progetto: rforge/muste
static int linreg(double *X,double *Y,double *S,double *U,double *T,double *B,double *R,int m,int n) {
// RS REM  int i;
  mat_store(X,T,m,n);
  if (mat_gram_schmidt(S,U,T,m,n,TOLERANCE)<0) {
    sur_print("\nUnable to solve!");
//    showmatrix(X,m,n);    
    WAIT; return(-1);
  }
  mat_transp(T,S,m,n);
  mat_mlt(S,T,Y,n,m,1);
  solve_upper(B,U,S,n,1,TOLERANCE);

  fixmat(B,n);

  return(residual(R,B,Y,X,m,n));
}
Esempio n. 4
0
int main(){
    int kadai;

    // 課題番号指定
    while(1){
        printf("課題番号: ");
        scanf("%d", &kadai);
        if (kadai < 1 || kadai > 8 || kadai == 7){
            printf("1~8!!\n");
        } else {
            break;
        }
    }

    if (kadai == 1){

        double coefficient_mat[N][N] = {{1, 0, 0}, {3, 1, 0}, {-2, 2, 1}};
        double right_hand_vec[N] = {2, 3, -1};
        double solution_vec[N];

        printf("--------------- L行列 ---------------\n");
        print_array(coefficient_mat);
        printf("------------- 右辺ベクトル ------------\n");
        print_vector(right_hand_vec);

        forward_substitution(coefficient_mat, right_hand_vec, solution_vec);

        printf("------------- 解ベクトル --------------\n");
        print_vector(solution_vec);

    } 
    else if (kadai == 2)
    {

        double coefficient_mat[N][N] = {{2, 1, -1}, {0, 3, 2}, {0, 0, -3}};
        double right_hand_vec[N] = {2, -3, 9};
        double solution_vec[N];

        printf("--------------- U行列 ----------------\n");
        print_array(coefficient_mat);
        printf("------------- 右辺ベクトル -------------\n");
        print_vector(right_hand_vec);

        backward_substitution(coefficient_mat, right_hand_vec, solution_vec);

        printf("-------------- 解ベクトル -------------\n");
        print_vector(solution_vec);

    }
    else if (kadai == 3)
    {

        double coefficient_mat[N][N];
        double l_matrix[N][N] = {{1, 0, 0}, {3, 1, 0}, {-2, 2, 1}};
        double u_matrix[N][N] = {{2, 1, -1}, {0, 3, 2}, {0, 0, -3}};

        mat_mlt(l_matrix, u_matrix, coefficient_mat);

        printf("---------- 係数行列 ----------\n");
        print_array(coefficient_mat);

    }
    else if (kadai == 4)
    {

        double coefficient_mat[N][N] = {{2, 1, -1}, {6, 6, -1}, {-4, 4, 3}};
        double l_matrix[N][N] = {0};
        double u_matrix[N][N] = {0};

        lu_decomposition(coefficient_mat, l_matrix, u_matrix);

        printf("---------- L行列 ----------\n");
        print_array(l_matrix);
        printf("---------- U行列 ----------\n");
        print_array(u_matrix);

    }
    else if (kadai == 5)
    {

        double coefficient_mat[N][N] = {{2, 1, -1}, {6, 6, -1}, {-4, 4, 3}};
        double right_hand_vec[N] = {2, 3, -1};
        double solution_vec[N];

        printf("---------- 係数行列 ----------\n");
        print_array(coefficient_mat);
        printf("---------- 右辺ベクトル ----------\n");
        print_vector(right_hand_vec);

        solute_SLE_with_n_variables(coefficient_mat, right_hand_vec, solution_vec);

        printf("---------- 解ベクトル ----------\n");
        print_vector(solution_vec);

    }
    else if (kadai == 6)
    {

        double h_coefficient_mat[N][N];
        double right_hand_vec[N];
        double solution_vec[N];

        int i, j;
        for (i = 0; i < N; i++){
            for (j = 0; j < N; j++){
                h_coefficient_mat[i][j] = pow(0.5, abs(i-j));
            }
        }
        printf("--------------- 行列H ---------------\n");
        print_array(h_coefficient_mat);

        for (i = 0; i < N; i++){
            right_hand_vec[i] = 3 - pow(2, i-N+1) - pow(2, -i);
        }
        printf("------------- 右辺ベクトル -------------\n");
        print_vector(right_hand_vec);

        solute_SLE_with_n_variables(h_coefficient_mat, right_hand_vec, solution_vec);

        printf("---------- 解ベクトル ----------\n");
        print_vector(solution_vec);

    }
    else if (kadai == 8)
    {

        double h_mat[N][N];
        double h_reverse_mat[N][N] = {0};
        double solution_mat[N][N];

        int i, j;
        for (i = 0; i < N; i++){
            for (j = 0; j < N; j++){
                h_mat[i][j] = pow(0.5, abs(i-j));
            }
        }

        evaluate_reverse_matrix(h_mat, h_reverse_mat);

        mat_mlt(h_mat, h_reverse_mat, solution_mat);
        printf("--------------- 行列H ---------------\n");
        print_array(h_mat);
        printf("------------ 行列Hの逆行列 ------------\n");
        print_array(h_reverse_mat);
        printf("---------- 解行列 ----------\n");
        print_array(solution_mat);
    } 

    return 0;
}