/* Solve arbitrary potential problem in 1-D */ /* by inverting scattering matrix h[][] */ /* of quantum boundary conditions */ /* scattering solutions only. */ /* The number of lattice points in potential */ /* region is (MAX-2)/2, the array determines */ /* the coefficients R,T, A_i, B_i */ /* for i=1,2,...,(MAX-2)/2 */ /* dx should be chosen accordingly */ /* the lattice points are at matching boundary */ /* points */ #include #include #include #include #define PI 3.1415926 #define MAX 100 /* maximum array size */ #define N 99 /* 1 less than MAX; passed to inversion algorithm */ _Complex double h[MAX][MAX], hinv[MAX][MAX]; _Complex double R,T,A,B; double dx,x,E,dE; double V(double x); /* potential function used to get k[] */ double k[MAX/2-1]; /* array to hold momenta */ double X[MAX/2-1]; /* array to hold boundary match points */ int i,j,l,m; char c; void cinverse(_Complex double (*A)[N+1],_Complex double (*Ainv)[N+1]); double modulus(_Complex double c); main(){ _Complex double (*h_ptr)[MAX], (*h_invptr)[N+1]; dx=0.1; /* axis increments */ dE=0.05; for(l=1;l<=500;l++){ E=(double)l*dE; /* set the incoming wave energy */ k[0]=sqrt(2.0*E); for(m=1;m<=MAX/2-1;m++){ /* creation of k-vectors */ k[m]=csqrt(2.0*E+2.0*V((double)m*dx-dx/2.0)) ; X[m]=(double)m*dx;} /* set up array of matching points */ X[0]=0.0; /* create the matrix to be inverted */ for (i = 0; i < MAX; i++) { for(j = 0;j < MAX; j++){ hinv[i][j]=0.0; h[i][j]=0.0; } } for(m=0;m=0;k--){ for(l=k-1;l>=0;l--){ factor=*(*(A+k)+l)/ *(*(A+k)+k); for( j=0;j<=N;j++){ *(*(A+j)+l)=*(*(A+j)+l)-factor * *(*(A+j)+k); one[j][l]=one[j][l]-factor*one[j][k];}}} /* Now put together the inverse */ for(col=0;col<=N;col++){ for(row=0;row<=N;row++){ one[col][row]=one[col][row]/ *(*(A+row)+row); *(*(Ainv+col)+row)=one[col][row];}} return ; } double V(double x) { if(x<1.0 || x>3.0) return(0.0); else return(4.0); } double modulus(_Complex double c) { double re,im; re=creal(c); im=cimag(c); return(re*re+im*im); }