Selasa, 28 Mei 2013

[bs] Osilator Harmonik


Matlab code :

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Quantum mechanic I, page 138                   %             
% Computing osilation psi_v2                     %       
% Andri Husein, 27 Mei 2013                      %    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all
close all
clc

hbar  = 1.054e-34;    % Plank's constant
melec = 9.1e-31;      % Mass of an electron
eVtoJ = 1.6e-19;      % Energy conversion factors eV to Joule
E0 = 13.6*eVtoJ;

delta_x = .1e-11;
x_min = -300;
x_max =  300;
dx    = (x_max - x_min)/300;

x = (x_min:dx:x_max)*delta_x; % a.u

syms y;
n = 0;
omega0  = 2*E0/hbar;
alpha0  = sqrt(melec*omega0/hbar);
N0      = sqrt(alpha0/sqrt(pi));
h0      = 1;

qu = 8;
for s=1:qu
    n=n+1;
    E(s)=(n+0.5)*E0;
    omega(s) = E(s)/hbar;  
    alpha(s) = sqrt(melec*omega(s)/hbar);   
    N(s)= sqrt(alpha(s)/((2^n)*factorial(n)*sqrt(pi)));   
    h(s) = (-1)^n*exp(y.^2)*diff(exp(-y^2),y,n);
   
end
EE       = [E0 E];
w        = [omega0 omega];
alph     = [alpha0 alpha];
Normal   = [N0 N];
Hermit   = [h0 h];
V = 0.5*melec*w(6)^2*x.^2;

for s=1:qu+1;
psi(s) = Normal(s)*Hermit(s)*exp(-y^2/2);
end
psi_1=subs(psi(1),y,alph(1)*x);
psi_2=subs(psi(2),y,alph(2)*x);
psi_3=subs(psi(3),y,alph(3)*x);
psi_4=subs(psi(4),y,alph(4)*x);
psi_5=subs(psi(5),y,alph(5)*x);
psi_6=subs(psi(6),y,alph(6)*x);
psi_7=subs(psi(7),y,alph(7)*x);
psi_8=subs(psi(8),y,alph(8)*x);
psi_9=subs(psi(9),y,alph(9)*x);

h = figure(1);
set(h,'Position',[100 100 800 500]);% frame position to display
set(gcf,'Color',[1 1 1])

T  = 0;
dt = 5e-18;
i = sqrt(-1);
photo = 0;
for t_step=1:200
    photo=photo+1;
    T = T+1;
    y1(t_step)=exp(-i*w(1)*T*dt);
    y2(t_step)=exp(-i*w(2)*T*dt);
    y3(t_step)=exp(-i*w(3)*T*dt);
    y4(t_step)=exp(-i*w(4)*T*dt);
    y5(t_step)=exp(-i*w(5)*T*dt);
    y6(t_step)=exp(-i*w(6)*T*dt);
    y7(t_step)=exp(-i*w(7)*T*dt);
    y8(t_step)=exp(-i*w(8)*T*dt);
    y9(t_step)=exp(-i*w(9)*T*dt);
   
    PSIX_1=psi_1*y1(t_step);
    PSIX_2=psi_2*y2(t_step);
    PSIX_3=psi_3*y3(t_step);
    PSIX_4=psi_4*y4(t_step);
    PSIX_5=psi_5*y5(t_step);
    PSIX_6=psi_6*y6(t_step);
    PSIX_7=psi_7*y7(t_step);
    PSIX_8=psi_8*y8(t_step);
    PSIX_9=psi_9*y9(t_step);
   
    plot(x,PSIX_1*1e-5+1,'r','LineWidth',2)
    axis([-3*1e-10 3*1e-10 0 19])
    hold on
    plot(x,PSIX_2*1e-5+3,'g','LineWidth',2)
    plot(x,PSIX_3*1e-5+5,'b','LineWidth',2)
    plot(x,PSIX_4*1e-5+7,'m','LineWidth',2)
    plot(x,PSIX_5*1e-5+9,'y','LineWidth',2)
    plot(x,PSIX_6*1e-5+11,'c','LineWidth',2)
    plot(x,PSIX_7*1e-5+13,'r','LineWidth',2)
    plot(x,PSIX_8*1e-5+15,'g','LineWidth',2)
    plot(x,PSIX_9*1e-5+17,'b','LineWidth',2)   
    plot(x,V*(19/5e-16),'k--','LineWidth',2)   
    hold off
    text(1.5*1e-10,18,sprintf('t = %5.3f fs',T*dt*1e15),'fontsize',14);
    text(-2.5*1e-10,1.4,sprintf('n = 0'),'fontsize',14);
    text(-2.5*1e-10,3.4,sprintf('n = 1'),'fontsize',14);
    text(-2.5*1e-10,5.4,sprintf('n = 2'),'fontsize',14);
    text(-2.5*1e-10,7.4,sprintf('n = 3'),'fontsize',14);
    text(-2.5*1e-10,9.4,sprintf('n = 4'),'fontsize',14);
    text(-2.5*1e-10,11.4,sprintf('n = 5'),'fontsize',14);
    text(-2.5*1e-10,13.4,sprintf('n = 6'),'fontsize',14);
    text(-2.5*1e-10,15.4,sprintf('n = 7'),'fontsize',14);
    text(-2.5*1e-10,17.4,sprintf('n = 8'),'fontsize',14);
   
    set(gca,'fontsize',14)
    xlabel('x (meter)')
    ylabel('\psi (x,t)')
    set(gca,'YTick',0:4:19)
    box off
      

M(t_step)=getframe(h);
%M=getframe(h);
%[X, map] = frame2im(M);
%imwrite(X,['fig' ,num2str(photo),'.png']);
end
movie2avi(M,'Osilator.avi', 'compression', 'none')

Referensi :

Dra. Suparmi, M.A., Ph.D, Mekanika Kuantum I, Jurusan Fisika Fakultas MIPA, Universitas Sebelas Maret, Surakarta, ISBN 978-602-99344-1-0, pages 121 - 138, Juli 2011.


Tidak ada komentar :