// Submitted by Dr. Triranjita Srivastava. Assistant Professor, Physics Dept., Kalindi College, University of Delhi

// Aim: To show the commutator relation in postion and momentum space [x,p]=ih_cut or n general [x^n,p]=i*h_cut*n*x^(n-1)
// Two examples are shown in this program
//1. Let the first function is fx=x
//2. Let the second function is fx=x^3
// For simplicity let the wavefunction A=x 
//[fx,p]=(ih_cut)(dfx/dx)
//h_cut=h/2pi; h is planck constant


clc
x=poly(0,"x")
h_cut=1.05*(10)^-34                 //h_cut=h/2pi, units is in Joule-sec
A=x                                 //Considered Wavefunction is A=x

s=input("Enter 1 or 2 to choose the function as fx = x or fx = x^3, s= ")
select s
case 1
    fx=x                             //First wavefunction 
case 2
    fx=x^3               //Second wavefunction 
end

fx_p=fx*(-%i*h_cut)*derivat(A)
p_fx=(-%i*h_cut)*derivat(fx*A)
commutator=(fx_p-p_fx)
disp("[fx,p] = ")
disp(commutator)
disp ("The result contains an extra x because the chosen wavefunction is A = x")





