Variational method on 1D potential well using plane wave basis

Leave a comment

The potential is

V(x) = \left \{ \begin{matrix} - V_0 & , -L/2 \leq x \leq L/2 \\ 0 & , else \end{matrix} \right \}

The exact solution can be solved by matching boundary condition.

\tan(\sqrt{\frac{2m}{\hbar^2}(E+V_0 ) \frac{L}{2}}) = \sqrt{\frac{|E|}{E+V_0}}

The plane wave basis is

b_n(x) =\frac{1}{\sqrt{a}} \exp\left( i \frac{2\pi}{a} n x \right)

The matrix of the Hamiltonian is

\displaystyle H_{ij} = \langle b_i | \frac{P^2}{2m} + V(x) | b_j \rangle

\displaystyle \langle b_i | \frac{P^2}{2m} | b_j \rangle = \delta_{ij} \frac{L}{a}\frac{\hbar^2}{2m} \left(\frac{2\pi}{a}\right)^2 i^2

\displaystyle \langle b_i | V(x) | b_j \rangle = -V_0 \frac{L}{a} \frac{\sin( \pi (i-j) L/a)}{\pi (i-j) L/a}

Then, we solve for the eigen system.

I use mathematica for solving the eigen system.

For simplicity, I set L = 2, V_0 = 1. The exact solution is E = -0.603898 .

The parameter a controls the wavelength of the plane wave. By increasing the number of wave n , we effectively control the minimum wavelength \lambda_0 = a/n Therefore, larger the n, the energy will approach to the actual value.

I generated a from 10 to 200 with step 10, and n from 5 to 60 with step 5. Here is the result. As we can see, the larger the a, we need more number of wave to go to the actual energy. When small a and large n , the result quickly converge to the actual energy. For n = 60, a = 40 , the energy is E = -0.603792, the difference is \Delta E = 0.000106 or 0.02% difference.


The following plot show a = 40


However, when the a is too small, the plane wave cannot describe the actual wave function, then the converge fail. The following plot show n = 60


To investigate, I plot the case for a = 3 and a = 10.


We can see, since the well width is 2, if the maximum wavelength is only 3, then it cannot capture a longer wavelength component. And we can see the calculated wave functions are repeated.


Wireless charger stand

Leave a comment

I made a stand for the Samsung wireless charger using inventor.

First, creates a part for the charger and a part for the phone (I am using note 5). Then derive them into another part, and we can cut a shape of the charger.

I attach the inventor files in here. The zip file also contained a stl file for 3D printing.

Here is the draft and the product. The drawing of the charger is not perfect matched. Anyway, feel free to modify.

2017-10-03 16.33.50Capture2.PNG

Here are the design consideration.

  1. For vertical, the placement of the phone must be centered with the charger, so that once the phone is placed, it charges.
  2. Possible horizontal placement.
  3. Able to connect USB and ear phone, for video chatting.
  4. The base size should not larger than the charger.
  5. The charger should “sit” securely.
  6. The USB cable can go to any side.
  7. Minimum supportive material for 3D printing
  8. 4 corner legs are made, because the base is usually not clean for 3D printing.
  9. those legs are small, so easy to polish, so that they are co-planar.
  10. Edges should be smooth.

Qt source code for controlling Omron E5CC

Leave a comment

These 2 weeks I was fiighting with the manual and try to control the device.

In my application, I need to change the temperature super slowly, not jump from 1 point to the other. I heard that there is an internal function called SP-ramp, that seem to fit my purpose, but I don’t really understand the manual….

The program can control most basic functions, record temperature, set the change rate of SP, limit the output (MV).

However, I don’t know how to get the RUN/STOP and AT (Auto-tune) status, so be careful.

The source code is in Github, feel free to download and modify. The program use Modbus for communication, so, you need to set the device.

I also made a simplified manual, but I do not post in here for copyright issue. If you want, leave a massage.

Reason for n>l in atomic orbit

Leave a comment

If we study atomic structure, we will find the principle quantum number must larger than azimuthal quantum number (the number of angular momentum), i.e.

n > l

But most text book give this result using mathematics that there is no solution for the radial equation when n \leq l. Some text book solves the radial equation using power series, and argue that the series has to be terminated at power of n-1 because the number of node is n-1. The exactly solution is related to Laguerre polynomial, and the polynomial is only defined for n \geq l+1 .

Also, in nuclear physics, there is no restriction and n and l can take any integers. Why these two cases are different? of course, the key point is the potential difference. Coulomb potential is used in atomic orbit. Wood-Saxon potential (or finite square well ) is used in nuclear orbit.

The Schrodinger equation for potential V(r) is

\displaystyle  \left( \frac{1}{r^2} \frac{\partial}{\partial r}\left( r^2 \frac{\partial}{\partial r}\right) - \frac{1}{r^2} L^2 - \frac{2m}{\hbar^2} V(r) \right) \psi(r, \Omega) = -\frac{2mE}{\hbar^2} \psi(r,\Omega)

Separate the radial and spherical part \psi(r, \Omega) = R(r) Y(\Omega)

\displaystyle L^2 Y(\Omega) = l(l+1) Y(\Omega)

\displaystyle  \left( \frac{1}{r^2} \frac{d}{d r}\left( r^2 \frac{d}{d r}\right) - \frac{l(l+1)}{r^2} - \frac{2m}{\hbar^2} V(r) \right) R(r) = -\frac{2mE}{\hbar^2} R(r)

The radial equation further reduce by using u(r) = r R(r)

\displaystyle \frac{d^2 u}{dr^2} - \frac{2m}{\hbar^2} U(r) u(r) = \frac{2mE}{\hbar^2} u(r)

we can see, the effective potential is

\displaystyle  U(r) =   V(r) + \frac{\hbar^2}{2m} \frac{l(l+1)}{r^2}  

For Coulomb potential,

\displaystyle U(r) = -\frac{e^2}{4\pi \epsilon_0 r} + \frac{\hbar^2}{2m} \frac{l(l+1)}{r^2}

Introduce dimensionless quantities, or Express everything using the fine structure constant. a_0 is Bohr radius,

\displaystyle \rho = \frac{2r}{a_0},  \lambda = \frac{e^2}{4\pi \epsilon_0} \sqrt{ - \frac{m}{2\hbar^2 E}}  =  n

The equation becomes

\displaystyle \frac{d^2u}{d\rho^2} + \left(\frac{\lambda}{\rho} - \frac{l(l+1)}{\rho^2}\right) u = \frac{1}{4} u

The simplified effective potential,

\displaystyle U(\rho) = \frac{n}{\rho} - \frac{l(l+1)}{\rho^2} 

Now, we related the principle quantum number and azimuthal quantum number in one simply formula.

Since the repulsive part due to the rotation is getting larger and larger, the minimum point of the effective potential is

\displaystyle \rho_{min} = \frac{2l(l+1)}{n}

When l = n, \rho_{min} = 2(n+1) , r_{min} = (n+1)a_0 .

I plot the case for n=2


The bottom line is l = 0. We can see, when l = 2, the minimize point of the potential is at r = 3 a_0 . The potential is vary shallow, and the bound state is very diffuses. Since the 2nd derivative of the wave function u around the minimum point is

\displaystyle \frac{d^2u}{d\rho^2} = \left( \frac{l(l+1)}{\rho^2} - \frac{n}{\rho} + \frac{1}{4} \right) u \approx \frac{1}{4} \frac{l(l+1) - n^2}{l(l+1)} u = k u

For l = n-1 , k is negative, that give oscillating wave function.

For l = n, k is positive, that gives explosive wave function that cannot be normalized.

Therefore, l < n .

In fact, if we plot the effective potential,

\displaystyle U(r) = -\frac{e^2}{4\pi \epsilon_0 r} + \frac{\hbar^2}{2m} \frac{l(l+1)}{r^2}

we can find that when l \geq 1, the potential is also very shallow. For such a picture, we can see the wave function must be oscillating that the number of node must be larger then 1, so the principle quantum number should be larger than 1.

In nuclear orbit, the effective potential using Wood-Saxon potential is

\displaystyle U(r) = -\frac{1}{1-\exp(\frac{r-R}{a})} + \frac{\hbar^2}{2m} \frac{l(l+1)}{r^2}

where $R \approx 1.25 A^{1/3} [fm]$ and a = 0.6 [fm]. For simplicity, we use

\displaystyle U(r) = -\frac{1}{1-\exp(\frac{r-R}{a})} + \frac{l(l+1)}{r^2}

The position of minimum potential is no simple formula. I plot R=10,  a=1


We can see, for any l < l_{u} there is a “well” that can bound a nucleon.

I haven’t solve the finite spherical well, but the infinite spherical well is solved. The solution is the spherical Bessel function of first kind. that function only has 1 parameter, which is the angular momentum. To determine the energy is simply find the node position, and the number of node is related to the principle quantum number. Therefore, the principle quantum number and angular momentum is unrelated. A similar result should be applied well in the case of finite spherical well like Wood-Saxon type, that, for a fixed angular momentum, there can be many solution with different number of nodes.

Wood-Saxon potential, the effective potential is always sloping, especially when outside of the well, that forces that wave function to be decay faster. However, the Coulomb potential is a long range force, the effective potential can be slowly changing for long distance, that allow the wave function to be oscillating for long range.

Express Hydrogen orbit using fine structure constant

Leave a comment

The fine structure constant is

\displaystyle \alpha = \frac{e^2}{4\pi \epsilon_0} \frac{1}{\hbar c}

The Bohr radius

\displaystyle a_0 = \frac{4\pi \epsilon_0}{e^2} \frac{\hbar^2}{m} = \frac{\hbar}{m c \alpha}

The energy

\displaystyle E_n  = -\frac{1}{2n^2} \left(\frac{e^2}{2\pi \epsilon_0}\right)^2 \frac{m}{\hbar^2} = - \frac{1}{2} m (c\alpha)^2 \frac{1}{n^2}

We can remember that the electron is traveling at \alpha c at ground state.

When solving the radial part of the schrodinger equation, we can use

\displaystyle \rho = \frac{2r}{a_0} = r\sqrt{- \frac{8mE}{\hbar^2}}

\displaystyle \lambda = n = \sqrt{ -\frac{mc^2 \alpha^2}{2 E}}

Omron E5CC Modbus RTU in QT 101

Leave a comment

The Omron E5CC temperature PID controller is using modbus RTU(Remote Terminal Unit) to connect.

First, you prepare a USB-to-RS-485 cable. Connect it to the E5CC. Notice that the A port of the E5CC, should be connected to  negative of the RS-485. Don’t follow the E5CC manual. Also the programing manual is extremely for expert of modbus, not for beginner.

In Modbus, the idea is that, your PC (master) send signal over the connected devices (slaves). The signal is a Hex, contained few things

DeviceID + Function-Code + Address + Command-in-Hex + CRC-16

The master send a signal, only the device with matching DeviceID will respond to the signal. Thus, there is no “locking” that link the master-slave.

The Function-Code is modbus function code, it tell the type of the signal. The type can be reading, writing, diagnostic, etc. This function is part of the modbus protocol, which is common for all devices.

The Address is the memory address stored in the device. The address should be provided by the device manufacture.

Then the command-in-Hex follow.

At the end, a 4-digit Hec CRC-16 is used for error check. Qt can calculate CRC-16 for modbus.

Read single value

In the Omron E5CC programing manual. Section 4-4-1, we see that the data structure of a read signal. It is read because the Function-Code is 0x03, which is  “Read Holding Registers” in modbus RTU protocal. For example, reading the temperature (PV) of E5CC,

01 03 00 00 00 02 C4 0B

0x01 is deviceID, this can be set in the E5CC.

0x03 is the function code

0x0000 is the address

0x0002 is number of value we are going to read. In modbus, one value contains 4-digit Hex, or 0xHHHH. In E5CC, each parameter is stored as 8-digit Hex, or 0xHHHHHHHH. Thus the E5CC manual tell us to get 2 values for temperature reading.

0xC408 is the CRC-16

The device return

01 03 04 00 00 03 E8 FA 8D

04 is the number of 8-digit Bin (2-digit Hex = 8-digit Bin). Four of 8-digit Bin = 8-digit Hex.

00 00 03 E8 is the return value of the temperature, converted to DEC is 1000, which is 100.0 ºC.

Write single value

Run/Stop command

01 06 00 00 01 01 49 9A

0x06 is the “Write Single Register” function-Code

0x0000 is the address

0x0101 is the value that start the run/stop for E5CC.

When writing single value in E5CC, only address 0x0000 is allowed. Thus, to write the SV (set value, or SP = Set Point) we have to use write multiple value. (stupid….)

Write multiple value

The set the alarm upper and lower values

01 10 01 0A 00 04 08 00 00 03 E8 FF FF FC 18 8D E9

0x10 is the “Write Multiple Coils”

0x010A is the address of the alarm upper value

0x0004  is the 2 times number of value to be written. In our case, we want to write 2 value, thus the value is 0x4. The address of the next value would be 0x010A + 0x0002 = 0x010C. Since all value use 2 memory slots.

0x08 is the length of the input value. There are 2 value, each value is four 4-digit-Hex, so the input is 0x08.

0x000003E8 is the first value

0xFFFFFC18 is the 2nd value

This structure can also be use to write single value. If we want to change the SV (or Set Point) to 100 ºC. The address is 0x0106.

01 10 01 06 00 02 04 00 00 00 64

In Qt, there is an example for modus, call master. We can use it for simple I/O.

Here is a screenshot.


First, we go to Tools to setup the Setting


In the E5CC, you have to set the communication mod to be modbus. In modbus, the parity, data bits, and stop bits are no used.

Since we use USB, this is serial port. The port number can be found using

const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos) {
        qDebug("PortName     ="+info.portName())
        qDebug() <<"description  =" << (!info.description().isEmpty() ?  info.description() : blankString);
        qDebug() <<"manufacturer =" << (!info.manufacturer().isEmpty() ? info.manufacturer() : blankString);
        qDebug() <<"serialNumber =" << (!info.serialNumber().isEmpty() ? info.serialNumber() : blankString);
        qDebug() <<"Location     =" << info.systemLocation();
        qDebug() <<"Vendor       =" << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString);
        qDebug() <<"Identifier   =  << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString);

In my case, it is COM4, so I put COM4 in the port. Then connect.

The read the temperature. We set the Table (at the lower left corner) to be Holding Register. In the Read (left panel), Start Address is 0, and Number of values to be 2. In the Qt application output, we will see:

qt.modbus: (RTU client) Sent Serial PDU: 0x0300000002
qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x010300000002c40b
qt.modbus: (RTU client) Send successful: 0x0300000002
qt.modbus.lowlevel: (RTU client) Response buffer: “010304”
qt.modbus: (RTU client) Incomplete ADU received, ignoring
qt.modbus.lowlevel: (RTU client) Response buffer: “0103040000001cfbfa”
qt.modbus: (RTU client) Received ADU: “0103040000001cfbfa”

The PDU = Protocol Data Unit, ADU = Accessing Data Unit = DeviceID + PDU + CRC-16. In the last line, the received PDU is 0x03040000001c, the value is 0x0000 and 0x001c=28, which is 18 ºC.

The display in the GUI is:


Now, we try to stop the device.

In the write panel, Start address is 0x0000, and according to the E5CC programing manual, the value consist of two part


AA is the command code

BB is the value

From the manual, the command code for RUN/STOP, 0xAA=0x01, and for STOP 0xBB=0x01. Thus, the value is 0x0101. Then we press write.


The Qt application output is

qt.modbus: (RTU client) Sent Serial PDU: 0x0600000101
qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x010600000101499a
qt.modbus: (RTU client) Send successful: 0x0600000101
qt.modbus.lowlevel: (RTU client) Response buffer: “01”
qt.modbus: (RTU client) Modbus ADU not complete
qt.modbus.lowlevel: (RTU client) Response buffer: “010600000101499a”
qt.modbus: (RTU client) Received ADU: “010600000101499a”

And we can see there is a STOP display on the E5CC.

We can see, although the Holding Register is the same, in read, the function code is 0x03, in write, the function code is 0x06. In Qt manual, the QModBusPdu Class, we can see a list of Function-Code. (

This program is limited 10 address, so the operation is limited. This introduction is the basic, I think user can can study the Qt code to know how to use modbus, how to read and write signal. And people can read this website for another modbus 101.

Qt ActiveX COM

Leave a comment

I found that most of the google result is not beginner friendly or not teach-me-as-if-i-am-five enough. Although I am also a beginner, anyway, so. in windows

First, we have a *.dll file which is your ActiveX COM (Component Object Model), we need to register the dll. For convenient, lets say the name of the dll is myAxtiveXCOM.dll. Run command prompt as administrator,

    regsvr32.exe  myActiveXCOM.dll


It will display a massage box telling you the register is successful. Then we need to local the ClassID (CLSID). Open regedit, find myActiveXCOM.dll, then you will find something like



or the NAME of the dll.

Then, in Qt, *.pro, add

    QT += axcontainer


This is for local COM usage. Then,

    #include <QAxObject>


This enable to use QAxObject, which is an “extension” of QObject that included ActiveX.

    QAxObject *ax = new QAxObject();


Then, you can debug, it should be fine and without any error message if the dll is registered correctly.

The activeX COM maker should provide a list of functions. for example, we have

    int Connect(string device, int ID)

In QT,

    QVariant ans = ax->dynamicCall("Connect(QString&, int&)", "A", 2);


The dynamicCall is used to call the functions, the function augments has to be converted using Qt variable type. The dynamicCall will return the output. In the above example, Connect will return an integer, so ans will be like

QVariant(int, 1)

Since the dynamicCall can only pass a constant augment to the function of ActiveX COM. When some function is passed by reference, or the function will update the input argument. For example,

   void Get_Model_Number(String name)

Then we have to first create a QList<QVariant>

    QList<QVariant> myStr;
    myStr << "dummpy";
    ax->dynamicCall("Get_Model_Number(QString&)", myStr);


Then, the variable myStr will be update and the value will be changed.

Older Entries Newer Entries