// QC_Levine_PROBLEMS.cpp
// Copyright (c) Saturday & Sunday, December 5 - 6, 2026
// by James Pate Williams, Jr.
// Reference: Quantum Chemistry (c) 1974
// by Ira N. Levine Chapter 1
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
static void PROBLEM_1_2()
{
double e = 4.80324e-10; // elementary charge
double F = -79.0 * e * e /
std::pow(0.003e-10 * 0.003e-10 * 100.0, 2.0);
std::cout << std::scientific;
std::cout << std::setprecision(5);
std::cout << "PROBLEM 1.2\n";
std::cout << "F = " << F << " dynes\n";
std::cout << "F = " << F / 1.0e5 << " newtons\n";
}
static void PROBLEM_1_3()
{
double c = 299792458;
double h = 6.62607015e-34;
double m = 9.1093837139e-31;
double v = c / 137.0;
double wavelength = h / (m * v);
std::cout << std::scientific;
std::cout << std::setprecision(9);
std::cout << "PROBLEM 1.3\n";
std::cout << "Wavelength = " << wavelength;
std::cout << " meters\n";
std::cout << "Wavelength = " << 100.0 * wavelength;
std::cout << " centimeters\n";
std::cout << "Electron mass is its rest mass\n";
}
static void PROBLEM_1_9()
{
double p = 4.0 * std::atan(1.0);
double h = 4.135667696e-15; // in eV / Hz
double m = 9.1093837139e-31 * 1.0e3; // in grams
double E = 1000.0; // electron volts
double a = std::asin(2.0 * m * h / (1000.0 * 0.1));
double d = a * 180.0 / p;
std::cout << "PROBLEM 1.2 (a)\n";
std::cout << "alpha radians = " << a << '\n';
std::cout << "alpha degrees = " << d << '\n';
a = 1.0 * p / 180.0;
double w = 2.0 * m * h / (E * std::sin(a));
std::cout << "PROBLEM 1.2 (b)\n";
std::cout << "Slit Width = " << w << " in cm\n";
}
static void PROBLEM_1_13()
{
std::cout << "PROBLEM 1.2 (a)\n";
std::complex<double> za = { 0, 1 };
std::cout << "|i| = " << std::abs(za) << '\n';
double a = 2, pi = 4.0 * atan(1.0);
std::complex<double> zb = a * (std::cos(pi / 3.0) + std::sin(pi / 3.0));
std::cout << "PROBLEM 1.2 (b)\n";
double zbAbs = std::abs(zb);
double zbPhase = std::atan(std::sin(pi / 3.0) / std::cos(pi / 3.0));
std::cout << "|zb| = " << std::abs(zb) << '\n';
std::cout << "phase(zb) = " << zbPhase << '\n';
std::cout << "PROBLEM 1.2 (c)\n";
std::complex<double> zc = { 1.0, -2.0 };
std::cout << "| 1 - 2i | = " << std::abs(zc) << '\n';
double zcPhase = std::atan(-2.0 / 1.0);
std::cout << "phase(1 - 2i) = " << zcPhase << '\n';
}
int main()
{
PROBLEM_1_2();
PROBLEM_1_3();
PROBLEM_1_9();
PROBLEM_1_13();
return 0;
}
Blog Entry © Friday, December 4, 2026, by James Pate Williams. Jr. A Simple VariationMethod Calculation
Blog Entry (c) Tuesday, December 1, 2026, James Pate Williams, Jr. Solution of Systems of Linear Equations by James Pate Williams, Jr.
Blog Entry (c) Friday, November 27, 2026, by James Pate Williams, Jr. Learning Six Functions via Radial Basis Function Networks
Blog Entry (c) Tuesday, November 20, 2026, by James Pate Williams, Jr. Second and Third Virial Coefficients for the Noble Gases
Blog Entry (c) Monday, November 2, 2026, by James Pate Williams, Jr. Some Astrophysical Calculations
Blog Entry (c) Sunday, November 1, 2026, by James Pate Williams, Jr. Some Hard Sphere Calculations
References: “Introduction to Statistical Thermodynamics” (c) 1960 by Terrell L. Hill 8.14.2: Properties of Nobel Gases – Chemistry LibreTexts
First, we approximate the hard sphere second virial coefficient for the Noble Gases using Monte Carlo integration. Analytic integration yields:
B2(T) = 2 * pi * a ^ 3 / 3
Where a is the diameter of the atom. The volume utilized was V = X ^ 3 where X = 25.0 * 100.0 * a. Then we compute four cluster integrals.

// HardSphereZ3.cpp : This file contains the 'main' function.
// Program execution begins and ends there.
// Copyright (c) Sunday, November 1, 2026
// by James Pate Williams, Jr., BA, BS, MSwE, PhD
// all potential energy is for a hard sphere
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
// second virial coefficient
static double B2(double X, double a, int N)
{
double I = 0.0, V = X * X * X;
for (int n = 0; n < N; n++)
{
double x1 = (X * rand()) / RAND_MAX;
double x2 = (X * rand()) / RAND_MAX;
double y1 = (X * rand()) / RAND_MAX;
double y2 = (X * rand()) / RAND_MAX;
double z1 = (X * rand()) / RAND_MAX;
double z2 = (X * rand()) / RAND_MAX;
double r12 = std::sqrt(
std::pow(x1 - x2, 2.0) +
std::pow(y1 - y2, 2.0) +
std::pow(z1 - z2, 2.0));
if (r12 >= a)
I += 1.0;
}
return V * I / N;
}
// three particle cluster integral
static double Z30(double X, double a, int N)
{
double I = 0.0, V = X * X * X;
for (int n = 0; n < N; n++)
{
double x1 = (X * rand()) / RAND_MAX;
double x2 = (X * rand()) / RAND_MAX;
double x3 = (X * rand()) / RAND_MAX;
double y1 = (X * rand()) / RAND_MAX;
double y2 = (X * rand()) / RAND_MAX;
double y3 = (X * rand()) / RAND_MAX;
double z1 = (X * rand()) / RAND_MAX;
double z2 = (X * rand()) / RAND_MAX;
double z3 = (X * rand()) / RAND_MAX;
double r12 = std::sqrt(
std::pow(x1 - x2, 2.0) +
std::pow(y1 - y2, 2.0) +
std::pow(z1 - z2, 2.0));
double r13 = std::sqrt(
std::pow(x1 - x3, 2.0) +
std::pow(y1 - y3, 2.0) +
std::pow(z1 - z3, 2.0));
double r23 = std::sqrt(
std::pow(x2 - x3, 2.0) +
std::pow(y2 - y3, 2.0) +
std::pow(z2 - z3, 2.0));
double u = 0.0;
if (r12 >= a)
u += 1.0;
if (r13 >= a)
u += 1.0;
if (r23 >= a)
u += 1.0;
if (u > 0.0)
I += u;
}
return V * I / N;
}
// four particle cluster integral
static double Z40(double X, double a, int N)
{
double I = 0.0, V = X * X * X;
for (int n = 0; n < N; n++)
{
double x1 = (X * rand()) / RAND_MAX;
double x2 = (X * rand()) / RAND_MAX;
double x3 = (X * rand()) / RAND_MAX;
double x4 = (X * rand()) / RAND_MAX;
double y1 = (X * rand()) / RAND_MAX;
double y2 = (X * rand()) / RAND_MAX;
double y3 = (X * rand()) / RAND_MAX;
double y4 = (X * rand()) / RAND_MAX;
double z1 = (X * rand()) / RAND_MAX;
double z2 = (X * rand()) / RAND_MAX;
double z3 = (X * rand()) / RAND_MAX;
double z4 = (X * rand()) / RAND_MAX;
double r12 = std::sqrt(
std::pow(x1 - x2, 2.0) +
std::pow(y1 - y2, 2.0) +
std::pow(z1 - z2, 2.0));
double r23 = std::sqrt(
std::pow(x2 - x3, 2.0) +
std::pow(y2 - y3, 2.0) +
std::pow(z2 - z3, 2.0));
double r34 = std::sqrt(
std::pow(x3 - x4, 2.0) +
std::pow(y3 - y4, 2.0) +
std::pow(z3 - z4, 2.0));
double r41 = std::sqrt(
std::pow(x4 - x1, 2.0) +
std::pow(y4 - y1, 2.0) +
std::pow(z4 - z1, 2.0));
double u = 0.0;
if (r12 >= a)
u += 1.0;
if (r23 >= a)
u += 1.0;
if (r34 >= a)
u += 1.0;
if (r41 >= a)
u += 1.0;
if (u > 0.0)
I += u;
}
return V * I / N;
}
static double Z41(double X, double a, int N)
{
double I = 0.0, V = X * X * X;
for (int n = 0; n < N; n++)
{
double x1 = (X * rand()) / RAND_MAX;
double x2 = (X * rand()) / RAND_MAX;
double x3 = (X * rand()) / RAND_MAX;
double x4 = (X * rand()) / RAND_MAX;
double y1 = (X * rand()) / RAND_MAX;
double y2 = (X * rand()) / RAND_MAX;
double y3 = (X * rand()) / RAND_MAX;
double y4 = (X * rand()) / RAND_MAX;
double z1 = (X * rand()) / RAND_MAX;
double z2 = (X * rand()) / RAND_MAX;
double z3 = (X * rand()) / RAND_MAX;
double z4 = (X * rand()) / RAND_MAX;
double r12 = std::sqrt(
std::pow(x1 - x2, 2.0) +
std::pow(y1 - y2, 2.0) +
std::pow(z1 - z2, 2.0));
double r23 = std::sqrt(
std::pow(x2 - x3, 2.0) +
std::pow(y2 - y3, 2.0) +
std::pow(z2 - z3, 2.0));
double r34 = std::sqrt(
std::pow(x3 - x4, 2.0) +
std::pow(y3 - y4, 2.0) +
std::pow(z3 - z4, 2.0));
double r41 = std::sqrt(
std::pow(x4 - x1, 2.0) +
std::pow(y4 - y1, 2.0) +
std::pow(z4 - z1, 2.0));
double r24 = std::sqrt(
std::pow(x2 - x4, 2.0) +
std::pow(y2 - y4, 2.0) +
std::pow(z2 - z4, 2.0));
double u = 0.0;
if (r12 >= a)
u += 1.0;
if (r23 >= a)
u += 1.0;
if (r34 >= a)
u += 1.0;
if (r41 >= a)
u += 1.0;
if (r24 >= a)
u += 1.0;
if (u > 0.0)
I += u;
}
return V * I / N;
}
static double Z42(double X, double a, int N)
{
double I = 0.0, V = X * X * X;
for (int n = 0; n < N; n++)
{
double x1 = (X * rand()) / RAND_MAX;
double x2 = (X * rand()) / RAND_MAX;
double x3 = (X * rand()) / RAND_MAX;
double x4 = (X * rand()) / RAND_MAX;
double y1 = (X * rand()) / RAND_MAX;
double y2 = (X * rand()) / RAND_MAX;
double y3 = (X * rand()) / RAND_MAX;
double y4 = (X * rand()) / RAND_MAX;
double z1 = (X * rand()) / RAND_MAX;
double z2 = (X * rand()) / RAND_MAX;
double z3 = (X * rand()) / RAND_MAX;
double z4 = (X * rand()) / RAND_MAX;
double r12 = std::sqrt(
std::pow(x1 - x2, 2.0) +
std::pow(y1 - y2, 2.0) +
std::pow(z1 - z2, 2.0));
double r23 = std::sqrt(
std::pow(x2 - x3, 2.0) +
std::pow(y2 - y3, 2.0) +
std::pow(z2 - z3, 2.0));
double r34 = std::sqrt(
std::pow(x3 - x4, 2.0) +
std::pow(y3 - y4, 2.0) +
std::pow(z3 - z4, 2.0));
double r41 = std::sqrt(
std::pow(x4 - x1, 2.0) +
std::pow(y4 - y1, 2.0) +
std::pow(z4 - z1, 2.0));
double r24 = std::sqrt(
std::pow(x2 - x4, 2.0) +
std::pow(y2 - y4, 2.0) +
std::pow(z2 - z4, 2.0));
double r31 = std::sqrt(
std::pow(x3 - x1, 2.0) +
std::pow(y3 - y1, 2.0) +
std::pow(z3 - z1, 2.0));
double u = 0.0;
if (r12 >= a)
u += 1.0;
if (r23 >= a)
u += 1.0;
if (r34 >= a)
u += 1.0;
if (r41 >= a)
u += 1.0;
if (r24 >= a)
u += 1.0;
if (r31 >= a)
u += 1.0;
if (u > 0.0)
I += u;
}
return V * I / N;
}
int main()
{
double pi = 4.0 * atan(1.0);
// radii of Noble Gases in picometers (10^-12 m)
const double Radii[6] = { 31, 38, 71, 88, 108, 120 };
// spherically symmetric atom's name
const std::string Names[6] = {
"Helium", "Neon", "Argon", "Krypton", "Xenon", "Radon" };
std::cout << "Hard Sphere Second Virial Coefficients for Noble Gases";
std::cout << std::endl;
std::cout << "Monte Carlo Integration is Used";
std::cout << std::endl;
std::cout << "B2(T)" << std::endl;
std::cout << "Atom\tExperiment\tTheory" << std::endl;
srand(1);
for (int i = 0; i < 6; i++)
{
double a = 2.0 * Radii[i] * 1.0e-12;
double X = 25.0 * 100.0 * a;
double b2 = B2(X, a, 1000000);
double bt = 2.0 * pi * std::pow(a, 3.0) / 3.0;
std::cout << Names[i] << "\t";
std::cout << std::scientific;
std::cout << std::setprecision(6);
std::cout << std::right;
std::cout << b2 << '\t';
std::cout << bt << std::endl;
}
std::cout << "Hard Sphere Configuration Integrals";
std::cout << std::endl;
std::cout << "Atom\tZ30\t\tZ40\t\tZ41\t\tZ42";
std::cout << std::endl;
for (int i = 0; i < 6; i++)
{
double a = 2.0 * Radii[i] * 1.0e-12;
double X = 25.0 * 100.0 * a;
double z30 = Z30(X, a, 1000000);
double z40 = Z40(X, a, 1000000);
double z41 = Z41(X, a, 1000000);
double z42 = Z42(X, a, 1000000);
std::cout << Names[i] << '\t';
std::cout << std::scientific;
std::cout << std::setprecision(6);
std::cout << std::right;
std::cout << z30 << '\t';
std::cout << z40 << '\t';
std::cout << z41 << '\t';
std::cout << z42 << '\t';
std::cout << std::endl;
}
return 0;
}
Blog Entry (c) Saturday, October 31, 2026, by James Pate Williams, Jr. Simple Maclaurin and Taylor Series Expansions
// MaclaurinSeries.cpp : This file contains the 'main' function.
// Program execution begins and ends there.
// Copyright (c) Saturday, October 31, 2026
// by James Pate Williams, Jr., BA, BS, MSwE, PhD
#include <cmath>
#include <iomanip>
#include <iostream>
// iterative n-factorial function
static double iFactorial(int n)
{
double factorial = 1.0;
for (int i = 2; i <= n; i++)
factorial *= i;
return factorial;
}
static double Series1(double x, int n)
{
double x2 = x * x, x4 = x2 * x2, x6 = x2 * x4;
switch (n)
{
case 0:
return 1.0;
case 1:
return 1.0 - x2;
case 2:
return 1.0 - x2 + 9 * x4 / iFactorial(4);
case 3:
return 1.0 - x2 + 9 * x4 / iFactorial(4) - 225 * x6 / iFactorial(6);
case 4:
return 1.0 - x2 + 9 * x4 / iFactorial(4) - 225 * x6 / iFactorial(6) +
10825 * x6 * x2 / iFactorial(8);
default:
return 0.0;
}
}
static double Series2(double x, int n)
{
double y = x - 1;
double y2 = y * y, y3 = y * y2, y4 = y * y3, y5 = y * y4;
double y6 = y * y5, y7 = y * y6, y8 = y * y7, y9 = y * y8;
double y10 = y * y9;
switch (n)
{
case 0:
return log(1.0);
case 1:
return log(1.0) + y;
case 2:
return log(1.0) + y - y2 / iFactorial(2);
case 3:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3);
case 4:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4);
case 5:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5);
case 6:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5)
- 120.0 * y6 / iFactorial(6);
case 7:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5)
- 120.0 * y6 / iFactorial(6) + 720.0 * y7 / iFactorial(7);
case 8:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5)
- 120.0 * y6 / iFactorial(6) + 720.0 * y7 / iFactorial(7)
- 5040.0 * y8 / iFactorial(8);
case 9:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5)
- 120.0 * y6 / iFactorial(6) + 720.0 * y7 / iFactorial(7)
- 5040.0 * y8 / iFactorial(8) + 40320 * y9 / iFactorial(9);
case 10:
return log(1.0) + y - y2 / iFactorial(2) + 2.0 * y3 / iFactorial(3)
- 6.0 * y4 / iFactorial(4) + 24.0 * y5 / iFactorial(5)
- 120.0 * y6 / iFactorial(6) + 720.0 * y7 / iFactorial(7)
- 5040.0 * y8 / iFactorial(8) + 40320 * y9 / iFactorial(9)
- 362880 * y10 / iFactorial(10);
default:
{
double sign = 1.0, sum = log(1.0);
for (int i = 1; i <= n; i++)
{
sum += sign * pow(y, i) / i;
sign *= -1.0;
}
return sum;
}
}
}
int main()
{
std::cout << "n" << '\t' << "n!" << std::endl;
for (int n = 0; n <= 10; n++)
std::cout << n << '\t' << iFactorial(n) << std::endl;
double x = 0.015;
std::cout << std::fixed << std::setprecision(10);
std::cout << "cos(arctan(x)) = (1 + x^2)^-1/2" << std::endl;
std::cout << "Maclaurin Series Expansion of (1 + x^2)^-1/2" << std::endl;
std::cout << "# is the number + 1 of nonzero terms in the summation\r\n";
std::cout << "x = " << x << std::endl;
std::cout << "#" << '\t' << "Series" << "\t\t" << "(1 + x^2)^-1/2";
std::cout << std::endl;
for (int n = 0; n <= 4; n++)
{
std::cout << n << '\t';
std::cout << std::fixed << std::setprecision(10);
std::cout << Series1(x, n) << '\t';
std::cout << pow(1.0 + x * x, -0.5) << std::endl;
}
x = 0.125;
std::cout << "Maclaurin Series Expansion of (1 + x^2)^-1/2" << std::endl;
std::cout << "x = " << x << std::endl;
std::cout << "#" << '\t' << "Series" << "\t\t" << "(1 + x^2)^-1/2";
std::cout << std::endl;
for (int n = 0; n <= 4; n++)
{
std::cout << n << '\t';
std::cout << std::fixed << std::setprecision(10);
std::cout << Series1(x, n) << '\t';
std::cout << pow(1.0 + x * x, -0.5) << std::endl;
}
x = 0.5;
std::cout << "Maclaurin Series Expansion of (1 + x^2)^-1/2" << std::endl;
std::cout << "x = " << x << std::endl;
std::cout << "#" << '\t' << "Series" << "\t\t" << "(1 + x^2)^-1/2";
std::cout << std::endl;
for (int n = 0; n <= 4; n++)
{
std::cout << n << '\t';
std::cout << std::fixed << std::setprecision(10);
std::cout << Series1(x, n) << '\t';
std::cout << pow(1.0 + x * x, -0.5) << std::endl;
}
x = 1.25;
std::cout << "Taylor Series Expansion of log(x)" << std::endl;
std::cout << "About x = 1" << std::endl;
std::cout << "x = " << x << std::endl;
std::cout << "#" << '\t' << "Series" << "\t\t" << "ln(x)";
std::cout << std::endl;
for (int n = 0; n <= 15; n++)
{
std::cout << n << '\t';
std::cout << std::fixed << std::setprecision(10);
std::cout << Series2(x, n) << '\t';
std::cout << std::log(x) << std::endl;
}
x = 1.5;
std::cout << "Taylor Series Expansion of log(x)" << std::endl;
std::cout << "About x = 1" << std::endl;
std::cout << "x = " << x << std::endl;
std::cout << "#" << '\t' << "Series" << "\t\t" << "ln(x)";
std::cout << std::endl;
for (int n = 0; n <= 30; n++)
{
std::cout << n << '\t';
std::cout << std::fixed << std::setprecision(10);
std::cout << Series2(x, n) << '\t';
std::cout << std::log(x) << std::endl;
}
return 0;
}
Blog Entry (c) Friday, October 30, 2026, by James Pate Williams, Jr. One-Component Classical Gas Second Virial Coefficient Calculated Using the Lennard-Jones Potential
Blog Entry (c) Wednesday, October 28, 2016, by James Pate Williams, Jr. One-Component Classical Monatomic Gas Second Virial Coefficient Using the Lennard-Jones Potential
// LennardJonesB2.cpp : This file contains the 'main' function.
// Program execution begins and ends there.
// Copyright (c) October 28, 2026
// by James Pate Williams, Jr., BA, BS, MSwE, PhD
#include <cmath>
#include <iomanip>
#include <iostream>
double gEpsilonKT = 0.0; // e / kT
double gRStar = 0.0; // r*
int gnSteps = 0; // number of Simpson's Rule steps
static double SimpsonsRule(
double a, double b, double(*fx)(double), int n)
{
double h = (b - a) / n;
double h2 = 2.0 * h;
double s = 0.0;
double t = 0.0;
double x = a + h;
for (int i = 1; i < n; i += 2)
{
s += fx(x);
x += h2;
}
x = a + h2;
for (int i = 2; i < n; i += 2)
{
t += fx(x);
x += h2;
}
return h * (fx(a) + 4 * s + 2 * t + fx(b)) / 3.0;
}
static double LennardJones(double epsilonKT, double y)
{
// epsilon = energy / kT
return exp(2.0 * epsilonKT * pow(y, -6.0) -
epsilonKT * pow(y, -12.0));
}
static double Integrand(double y)
{
// y = r / r*
double lj = LennardJones(1.0 / gEpsilonKT, y);
return -2.0 * 4.0 * atan(1.0) * pow(gRStar, 3.0) *
(lj - 1.0) * y * y;
}
static void PrintIntegral(double integral)
{
std::cout << std::fixed;
if (integral < 0.0)
{
std::cout << std::setprecision(10);
std::cout << integral;
}
else
{
std::cout << std::setprecision(11);
std::cout << ' ' << integral;
}
}
int main()
{
// assign global variables
gEpsilonKT = 1.0;
gRStar = 1.0;
gnSteps = 25000;
std::cout << "kT/e\tIntegral 1\tIntegral 2\t";
std::cout << "Integral 3" << std::endl;
while (gEpsilonKT <= 25.0)
{
double integral1 = SimpsonsRule(0.1, 25.0, Integrand, gnSteps);
double integral2 = SimpsonsRule(0.1, 50.0, Integrand, gnSteps);
double integral3 = SimpsonsRule(0.1, 75.0, Integrand, gnSteps);
std::cout << std::setprecision(2) << std::setw(2);
std::cout << static_cast<int>(gEpsilonKT) << '\t';
PrintIntegral(integral1);
std::cout << '\t';
PrintIntegral(integral2);
std::cout << '\t';
PrintIntegral(integral3);
std::cout << std::endl;
gEpsilonKT += 1.0;
}
return 0;
}