Download Computational Problem 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

T-symmetry wikipedia , lookup

Renormalization group wikipedia , lookup

Wave–particle duality wikipedia , lookup

Renormalization wikipedia , lookup

Matter wave wikipedia , lookup

Theoretical and experimental justification for the Schrödinger equation wikipedia , lookup

Particle in a box wikipedia , lookup

Transcript
CHEM 332
Physical Chemistry
Spring 2017
Computational Problem 1
Consider a particle of mass (m) in a Box with One Finite Wall:
This is a problem we considered in class. We will take as the problem parameters, those used in
the handout given in class:
m = 9.11 x 10-28g
L = 25Å
U = 16.02 x 10-20 J
We showed in class that the wavefunctions for the above three regions are given by:
I = 0
II = A
where II =
III = D
where  

We also showed the boundary conditions quantized the energies of the problem and that the
energy levels were the solutions to the following equation:
= -
This problem involves:
1)
Write a computer program to solve for the allowed energy levels for the problem as
specified. Your program must be written in C, C++, Java, FORTRAN or Python (since it
seems to be the flavor of the month). You programmed solution must implement a
Bisection algorithm. A handout describing that algorithm is available outside my office.
Program stubs in C++ and FORTRAN are attached. You may use these directly or you
may write your own program from scratch. A short primer of needed programming
constructs is also attached.
2)
Use your determined energy values to calculate  and II for each energy level.
3)
Calculate the ration A/D and then assume D = 1.
4)
Plot the resulting wavefunctions for each energy level.
Some Programming Constructs in C++
Memory Allocation for Variables
float a;
double a;
int a;
Assignment Operators
a = b + c;
a = a + b;
If-Then Construct
if ( logical expr )
{
statements;
}
or
if ( logical expr )
{
statements;
}
else
{
statements;
}
For Loop Construct
for (int k = 1, k < m, k++)
{
statements;
}
Logical Operators
&& = And
||
= Or
Other Operators
+, -, <, >, <=, >=
==
!=
Equal to
Not Equal to
Program Stub using C++
//Program by:
//Date:
//Program Name is PartBox.cpp
//These include statements make availaibe input/output routines and simple math fncs.
#include <iostream.h>
#include <math.h>
/*
Purpose: To use the Bisection Method (Numerical Analysis: Mathematics of Scientific
Computing, 3rd Ed; David Kincaid nad Ward Cheney; Pg. 76) to determine the quantized
energies for the Particle in a Box with One Finite Wall problem. Problem statement
in Quantum Chemistry, 2nd Ed.; John P. Lowe; Pgs. 40 - 41.
The particle's mass (M), width of the box (L) and the height of the finite wall (U)
are all fixed; although this requirement can easily be relieved.
The user will input the left and right ends of the possible energy interval (u, v),
the maximum number of attempts (m), the tolerance on the energy (delta) and the
tolerance on the function value (epsilon).
*/
const
const
const
const
const
double
double
double
double
double
M = 9.11e-31;
L = 25.0e-10;
U = 16.02e-20;
PI = 3.14159265358979323846;
H = 6.626068963e-34;
//Mass of the particle in kilograms.
//Width of the box in meters.
//Height of the finite wall in Joules.
//Value of the constant PI.
//Planck's Constant
double EnergyFnc(double eGuess);
//Purpose: To return the current value of the "Energy Function" based on the
//
current guess for the energy.
//
The Energy Function is: tan(2*PI*L*Sqrt(2*M*eGuess)/H) //
(Sqrt(eGuess)/Sqrt(U-eGuess)
//Receives: The current guess for the Energy.
//Return:
The value of the Energy Function.
int sign(double num);
//Purpose: To determine if a number is negative. No attempt is made to resolve
//
what happens at zero.
//Receives: The number whose sign is to be returned.
//Returns: -1 if the number is negative, 0 otherwise.
int main(void)
{
//User Inputs
double a;
double b;
int m;
double delta;
double epsilon;
//Intermediate Results
double u;
double v;
double w;
double e;
double c;
//Call for the user to input need parameters.
cout<<"Input Left End of Interval: ";
cin>>a;
cout<<"Input Right End of Interval: ";
cin>>b;
cout<<"Input Maximum Number of Attempts: ";
No input checking is performed.
cin>>m;
cout<<"Input Interval Tolerance: ";
cin>>delta;
cout<<"Input Function Tolerance: ";
cin>>epsilon;
*****IMPLEMENT YOUR ALGORITHM HERE*****
cout<<"Unable To Converge Before Max Attempts"<<endl;
return 0;
}
double EnergyFnc(double eGuess)
{
return (tan((2*PI*L*sqrt(2*M*eGuess))/H) + (sqrt(eGuess)/sqrt(U-eGuess)));
}
int sign(double num)
{
return (num < 0 ? -1 : 0);
}
Some Programming Constructs in FORTRAN
Memory Allocation for Variables
DOUBLE PRECISION A, B
INTEGER N, M
Assignment Operators
A=B+C
A=A+B
If-Then Construct
IF ( logical expr ) THEN
or
statements
IF ( logical expr ) THEN
statements
END IF
ELSE
statements;
END IF
Do Loop Construct
DO 10 K = 1, M, 1
statements
10 CONTINUE
Logical Operators
.AND. = And
.OR. = Or
Other Operators
+, -, .LT., .GT., .LE., .GE.
.EQ.
.NE.
Equal to
Not Equal to
Programming Stub using FORTRAN
PROGRAM PARTBOX
**********
*Program by:
*Date:
*Program Name is PartBox.f
**********
**********
*Purpose:
*
*
*
*
**********
To use the Bisection Method(Numerical Analysis: Mathematics of
Scientific Computing, 3rd Ed; David Kincaid and Ward Cheney;
P. 76) to determine the quantized energies for the Particle in
a Box with One Finite Wall problem. Problem statement in
Quantum Chemistry, 2nd Ed.; John P. Lowe; Pgs. 40-41.
**********
*MA = Particle's Mass
*L = Width of the Box
*UH = Height of the Potential Barrier
*PI = pi
*H = Planck's Constant
**********
DOUBLE PRECISION MA, L, UH, PI, H, ENFNC, A, B, DELTA,
.
EPSILO, U, V, W, E, C
PARAMTER (MA = 9.11D-31, L = 25.0D-10, UH = 16.02D-20,
.
PI = 3.14159265358979323846, H = 6.62608963D-34)
INTEGER SIGNOF, M, K
PRINT *, "INPUT LEFT END OF INTERVAL: "
READ *, A
PRINT *, "INPUT RIGHT END OF INTERVAL: "
READ *, B
PRINT * INPUT MAXIMUM NUMBER OF ATTEMPTS: "
READ *, M
PRINT *, "INPUT INTERVAL TOLERANCE: "
READ *, DELTA
PRINT *, "INPUT FUNCTION TOLERANCE: "
READ *, EPSILO
*****Implement Your Algorithm Here*****
PRINT *, "UNABLE TO CONVERGE BEFORE MAX ATTEMPTS"
END
**********
*Purpose: To return the current value of the "Energy Function" based
*
on the current guess for the energy.
**********
FUNCTION ENFNC(GUESS, MA, L, UH, PI, H)
DOUBLE PRECISION GUESS, MA, L, UH, PI, H, ENFNC
ENFNC = TAN((2.0*PI*L*SQRT(2.0*MA*GUESS))/H)
+ (SQRT(GUESS)/SQRT(UH-GUESS))
.
END
**********
*Purpose: To determine if a number is negative.
*
to resolve what happens at zero.
**********
FUNCTION SIGNOF(NUM)
INTEGER SIGNOF
DOUBLE PRECISION NUM
IF (NUM .LT. 0.0) THEN
SIGNOF = -1
No attempt is made
ELSE
SIGNOF = 0
END IF
END