0% found this document useful (0 votes)
4 views2 pages

Define The Constants // in Unit of J.S // in Unit of KG // It The Lenght of The Box

The document contains a C++ program that calculates the wavefunction, energy, and expectation value of a quantum particle in a one-dimensional box. It defines constants for Planck's constant, mass of the particle, and the length of the box, and includes functions to compute the wavefunction, energy, and expectation value based on user input. The program prompts the user for a quantum number and position, then outputs the corresponding wavefunction, energy, and expectation value in centimeters.

Uploaded by

Mukesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Define The Constants // in Unit of J.S // in Unit of KG // It The Lenght of The Box

The document contains a C++ program that calculates the wavefunction, energy, and expectation value of a quantum particle in a one-dimensional box. It defines constants for Planck's constant, mass of the particle, and the length of the box, and includes functions to compute the wavefunction, energy, and expectation value based on user input. The program prompts the user for a quantum number and position, then outputs the corresponding wavefunction, energy, and expectation value in centimeters.

Uploaded by

Mukesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

#include<cmath>

// Define the constants

const double h = 6.626e-34; // in unit of J.s

const double m = 9.1e-31; // in unit of kg

const double L = 0.01; // it the lenght of the box

// now i'm constructing the wavefunctions

double

wavefunction(int n, double x)

return ((sqrt(2.0 / L)) * (sin(n * M_PI * x / L)));

// Now i'm writing the formula for enrgy

double energy(int n)

return ((pow(n, 2) * pow(h, 2)) / (8 * m * pow(L, 2)));

// function for expectation value

double expectaction_x(int n, double x_start, double x_end, int steps = 1000)

double dx = (x_end - x_start) / steps;

double sum = 0.0;

for (int i = 0; i <= steps; i++)

double x = x_start + (i * dx);

double psi = wavefunction(n, x);


sum += x * pow(psi, 2) * dx;

return sum;

int main()

int n;

std::cout << "Enter quantum number n:";

std::cin >> n;

double x;

std::cout << "Enter position x(in cm):";

std::cin >> x;

x /= 100;

double psi = wavefunction(n, x);

std::cout << "Wavefunctin of " << n << " state at the position x = " << x * 100 << "cm is " << psi <<
std::endl;

double E = energy(n);

std::cout << "Energy of " << n << " state is " << E << "J" << std::endl;

double exp_x = expectaction_x(n, 0.0, 0.005);

std::cout << "Expectation value of x " << exp_x * 100 << "cm" << std::endl;

return 0;

You might also like