#include #include #include typedef double ftype; typedef ftype ** MATRIX; typedef ftype * VECTOR; typedef const ftype *const*const CONST_MATRIX; typedef const ftype * CONST_VECTOR; #define INIT_a 0.0 #define INIT_b 100.0 #define INIT_c 75.0 #define INIT_d 50.0 #define ERROR 0.000001 MATRIX matrix_alloc(int n, int m){ MATRIX x = (MATRIX)malloc(sizeof(ftype *)*n+sizeof(ftype)*n*m); int i; x[0]=(ftype *)(x+n); for(i=1;iN){ is_minus=-1; index-=N+1; } if(index==0){ TN[i][j]=0; }else{ TN[i][j]=sn[index-1]*mul*is_minus; } } for(i=0;iM){ is_minus=-1; index-=M+1; } if(index==0){ TM[i][j]=0; }else{ TM[i][j]=sm[index-1]*mul2*is_minus; } } } void TWODDST(MATRIX out, const MATRIX in) { int i; VECTOR tmp1=vector_alloc(N); VECTOR tmp2=vector_alloc(N); for(i=0;i=ERROR){//No solution, this element must be 0. failed=1; } tmp[i][j]=0.0; zero_count++; }else{ tmp[i][j]/=(2.0*cn[i]+1.0)*(2.0*cm[j]+1.0)-1.0; } } if(failed)return 0;//No solution available; TWODDST(x, tmp); return 1; } int IsValidSolution(MATRIX x) { int i,j; for(i=0;iERROR&&fabs(x[i][j]-1)>ERROR){ return 0; } } return 1; } void GaussSolve(const MATRIX kmatrix, VECTOR r,int order) { int i,j,k; MATRIX tmp=matrix_alloc(order,order); for(i=0;i