// qcalc.r -- This routine computes x and k space column vectors and // the q matrix that transforms between x and k space. // The three quantities are returned in a list. // // Input arguments -- // m -- number of components (must be a positive integer) // dx -- size of x grid cell // // To use this routine, first create x, k, and q. For example: // a = qcalc(201,1); // x = a.x; // k = a.k; // a = a.q; // // Next, construct a wave function and plot it to see what it looks like: // psi = exp(1i*x - x.*x/500); // pgplot([x,real(psi),imag(psi)]); // // Finally, transform to wavenumber space and see what the transformed // wave function looks like: // phi = q*psi; // pgplot([k,real(phi),imag(phi)]); // // How does phi change as the various characteristics of psi are // changed? qcalc = function(m,dx) { // check usage if (nargs != 2) { error("Usage: qcalc(m,dx)"); } // calculate x grid x = ([1:m]' - int((1 + m)/2))*dx; // calculate k grid pi = 4*atan(1); dk = 2*pi/(m*dx); k = ([1:m]' - int((1 + m)/2))*dk; // calculate the transformation matrix q = exp(-1i*k*x')/sqrt(m); // return stuff in a list return <>; }