```\n",
"    real*4      x(601), ...\n",
"\tcomplex*8   P(601), ...\n",
"\t...\n",
"\tdo j = 1,601\n",
"\t  x(j) = -75 + (j-1)*0.25\n",
"\t  P(j) = cmplx(0.,0.)\n",
"\tend do\n",
"```
\n", "\n", "C:\n", "
```\n",
"...\n",
"#include <math.h>\n",
"#include <complex.h>\n",
"\n",
"#define NPTS    601       /* these cannot be changed via command-line switches */\n",
"#define X_MIN   -75.0\n",
"#define X_MAX    75.0\n",
"...\n",
"  double dx,x[NPTS], ...;\n",
"  double complex Psi[NPTS];\n",
"...\n",
"  dx = (X_MAX-X_MIN)/(double)(NPTS-1);\n",
"  for (j=0; j < NPTS; j++) { \n",
"     x[j]=X_MIN + j*dx;\n",
"     Psi[j] = (double complex)0.0;  /* start with a blank Psi(x) */\n",
"     }\n",
"```
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fortran:\n", "
```\n",
"\tI = cmplx(0.,1.)\t!complex i\n",
"\n",
"\tk1 = sqrt(cmplx(E,0.))\n",
"\tK2 = sqrt(cmplx(E-1.,0.))\n",
"\n",
"\tC1 = -2*k1*K2-k1**2-2*k1*K2*exp(4*I*K2)+exp(4*I*K2)*k1**2\n",
"     *\t-K2**2+K2**2*exp(4*I*K2)\n",
"\n",
"\tb = (k1**2-K2**2)/ C1 *(exp(2*I*(2*K2-k1))-exp(-2*I*k1))\n",
"\tc = -2*k1*(K2+k1)/ C1 *exp(I*(K2-k1))\n",
"\td = (-2*K2+2*k1)*k1/ C1 *exp(I*(-k1+3*K2))\n",
"\tf = -4*k1*K2/ C1 *exp(2*I*(K2-k1))\n",
"```
\n", "\n", "C:\n", "
```\n",
"#include <complex.h>\n",
"...\n",
"  for (i=-n; i < n; i++) {\n",
"    p_now = p0 + (double)i * p_step;\n",
"    E = p_now*p_now;\n",
"    A = A0*exp(-pow((p_now-p0)/(2*s),2))*cexp(-I*(p_now*x0 + E*t));\n",
"\n",
"    k1 = csqrt((double complex)(E));\n",
"    k2 = csqrt((double complex)(E-U));\n",
"    ce4 = cexp(4*I*k2);\n",
"    C1 = -2*k1*k2-k1*k1-2*k1*k2*ce4+ce4*(k1*k1+k2*k2)-k2*k2;\n",
"\n",
"    b = (k1*k1-k2*k2)/ C1 *(cexp(2*I*(2*k2-k1))-cexp(-2*I*k1));\n",
"    c = -2*k1*(k2+k1)/ C1 *cexp(I*(k2-k1));\n",
"    d = (-2*k2+2*k1)*k1/ C1 *cexp(I*(-k1+3*k2));\n",
"    f = -4*k1*k2/ C1 *cexp(2*I*(k2-k1));\n",
"\n",
"    ...\n",
"  }\n",
"```
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fortran:\n", "
```\n",
"\tdo j = 1,296\t\t! left of the barrier, x < -1\n",
"\t  P(j) = P(j) + A * ( exp(I*k1*x(j)) + b*exp(-I*k1*x(j)) )\n",
"\tend do\n",
"\tdo j=297,304\t\t! inside the barrier, -1 < x < 1\n",
"\t  P(j) = P(j) + A * ( c*exp(I*K2*x(j)) + d*exp(-I*K2*x(j)) )\n",
"\tend do\n",
"\tdo j=305,601\t\t! to the right of the barrier, x > 1\n",
"\t  P(j) = P(j) + A * f*exp(I*k1*x(j))\n",
"\tend do\n",
"```
\n", "\n", "C:\n", "
```\n",
"    for (j=0; j < NPTS; j++) {\n",
"       if (x[j] < -1.) {         /* to the left of the barrier, x < -1 */\n",
"          Psi[j] += A*( cexp(I*k1*x[j]) + b*cexp(-I*k1*x[j]) );\n",
"          }\n",
"       else if (x[j] > 1.) {     /* to the right of the barrier, x > 1 */\n",
"          Psi[j] += A*f*cexp(I*k1*x[j]);\n",
"          }\n",
"       else {                    /* inside the barrier, -1 < x < 1 */\n",
"          Psi[j] += A*( c*cexp(I*k2*x[j]) + d*cexp(-I*k2*x[j]) );\n",
"          }\n",
"       }\n",
"```
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.5" } }, "nbformat": 4, "nbformat_minor": 2 }