Unrecognized function or variable
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Celso Júnior
el 18 de Abr. de 2022
Comentada: Walter Roberson
el 19 de Abr. de 2022
Goodnight! Whenever I run the following code, the error ''Unrecognized function or variable 'acav'.'' appears. Since the functions were all defined. Follow the codes. Anyone who can help me I would be very grateful.
clc
clear all
Nsim = 25; % Number of simulations
L = 2; % Number of cavities
wc = 1; % Cavity frequency
g = 1e-2* wc ; % Atom - light coupling
J = 1e-4* wc ; % Coupling between cavities
Nph = 2; % Number of photons per cavity
dimFock = Nph +1; % Dimension Fock space for photons
dimT = 2* dimFock ; % Dimension atom + cavity system
Deltai = 10^( -2) *g; % Initial detuning
Deltaf = 10^(+2) *g; % Final detuning
xi = log10 ( Deltai / g); % Initial detuning in log scale
xf = log10 ( Deltaf / g); % Final detuning in log scale
dx = (xf - xi ) /( Nsim -1) ; % Step dx
x = xi : dx : xf ; % Vector x to plot transition phase
OP_JC = zeros ( size (x) ); % Order parameter Jaynes - Cummings model
OP_R = zeros ( size ( x)); % Order parameter Rabi model
A = cell (1 , L); % Cell array to storage \hat{a}_i operators
Sp = cell (1 , L ); % Cell array to storage \ hat {\ sigma }_i ^+ operators
N_ex = cell (1 , L); % Cell array to storage N_i operators
Iatom = eye (2) ; % Identity matrix atom system
Icav = eye ( dimFock ); % Identity matrix cavity system
Is = eye (2* dimFock ); % Identity matrix atom + cavity system
accc
comple
for i =1:L
A{i} = acav(i ,L , Nph ,Is , Iatom ); % Photon operator \ hat {a}_i
Sp{i} = sigmap(i ,L ,Is , Icav ); % Atom operator \ hat {\ sigma }_i
N_ex {i} = A{i }'* A{i }+ Sp { i }* Sp {i }'; % number of excitations per cavity
end
Ad = ones (L); % Adyacent matrix
Ad = triu ( Ad ) - eye ( L); % A(i,j)=1 for j>i
Hhopp = zeros ( dimT ^L , dimT ^L); % Interaction Hamiltonian
for i =1: L
for j =1: L
Hhopp = Hhopp - J*Ad (i ,j)*A {i }'*A{j} - J*Ad (i ,j )*A{ i }*A{ j }';
end
end
Nt = 10000; % Length time vector
ti = 0.01/ J; % Initial time
tf = 1/ J ; % Final time
dt = (tf - ti ) /( Nt -1) ; % Step time dt
t = ti : dt : tf ; % Time vector
Lambda_R = zeros ( Nsim , Nt ) ;
Lambda_JC = zeros ( Nsim , Nt ) ;
parfor n =1: Nsim
D = g *10^( x(n) ); % Detuning in each simulation
Model = 'Rabi ';
[ OP_R(n) , P1m_R ] = QuantumSimulationCavityArray (wc ,D ,g , Nph ,L ,A ,Sp , N_ex , Hhopp ,t ,Model );
Model = 'Jaynes - Cummings ';
[ OP_JC(n ) , P1m_JC ] = QuantumSimulationCavityArray (wc ,D ,g , Nph ,L ,A ,Sp , N_ex , Hhopp ,t ,Model );
Lambda_R (n ,:) = -1/ L * log2 ( P1m_R ); % Rate function for the Rabi model
Lambda_JC (n ,:) = -1/ L * log2 ( P1m_JC ); % Rate function for the Jaynes - Cummings model
end
figure ()
box on
hold on
plot (J*t , Lambda_R (end ,:) ,'b-','Linewidth ' ,3)
plot (J*t , Lambda_JC (end ,:) ,'r-','Linewidth ' ,3)
hold off
xlabel ('$Jt$',' Interpreter ','LaTex ','Fontsize ', 30)
ylabel ('$\ Lambda (t)$',' Interpreter ','LaTex ','Fontsize ', 30)
set ( gca ,'fontsize ' ,21)
legend ({ '$\ mbox {RH }$ ','$\ mbox { JCH }$ '},' Interpreter ','latex ','Fontsize ', 21 , 'Location ','best ')
figure ()
box on
hold on
plot (x , real ( OP_R ) ,'.b','Markersize ' ,30)
plot (x , real ( OP_JC ) ,'.r','Markersize ' ,30)
hold off
xlabel ('$\ mbox { Log }_ {10}(\ Delta /g)$',' Interpreter ','LaTex ','Fontsize ', 30)
ylabel ('$\ mbox {OP }$ ',' Interpreter ','LaTex ','Fontsize ', 30)
set ( gca ,'fontsize ' ,21)
legend ({ '$\ mbox {RH }$ ','$\ mbox { JCH }$ '},' Interpreter ','latex ','Fontsize ', 21 , 'Location ','best ')
And the two functions accc and comple are defined as
Nsim = 25; % Number of simulations
L = 2; % Number of cavities
wc = 1; % Cavity frequency
g = 1e-2* wc ; % Atom - light coupling
J = 1e-4* wc ; % Coupling between cavities
Nph = 2; % Number of photons per cavity
dimFock = Nph +1; % Dimension Fock space for photons
dimT = 2* dimFock ; % Dimension atom + cavity system
Deltai = 10^( -2) *g; % Initial detuning
Deltaf = 10^(+2) *g; % Final detuning
xi = log10 ( Deltai / g); % Initial detuning in log scale
xf = log10 ( Deltaf / g); % Final detuning in log scale
dx = (xf - xi ) /( Nsim -1) ; % Step dx
x = xi : dx : xf ; % Vector x to plot transition phase
OP_JC = zeros ( size (x) ); % Order parameter Jaynes - Cummings model
OP_R = zeros ( size ( x)); % Order parameter Rabi model
A = cell (1 , L); % Cell array to storage \hat{a}_i operators
Sp = cell (1 , L ); % Cell array to storage \ hat {\ sigma }_i ^+ operators
N_ex = cell (1 , L); % Cell array to storage N_i operators
Iatom = eye (2) ; % Identity matrix atom system
Icav = eye ( dimFock ); % Identity matrix cavity system
Is = eye (2* dimFock ); % Identity matrix atom + cavity system
function [OP , P1m ]= QuantumSimulationCavityArray ( wc ,D ,g , Nphoton ,L ,A , Sp , N_ex , Hhopp ,t ,Model )
HJC = zeros (( Nphoton +1) ^L *2^ L ,( Nphoton +1) ^L *2^ L);
for i =1: L
switch Model
case 'Jaynes - Cummings '
HJC = HJC + wc *A{i }'* A{i } + (D+ wc )* Sp {i }* Sp {i }' + g *( Sp {i }* A{i }+ Sp {i }'* A{i}') ;
case 'Rabi '
HJC = HJC + wc *A{i }'* A{i } + (D+ wc )* Sp {i }* Sp {i }' + g *( Sp {i }+ Sp {i }') *( A {i }+ A {i }') ;
end
end
H = HJC + Hhopp ; % Total Hamiltonian
dt = t (2) -t (1) ; % Step time dt
U = expm ( -1i*H*dt ) ; % Time propagator with step dt
up = [1 0]'; % Excited state for the two - level system
down = [0 1]'; % Ground state for the two - level system
Fock = eye ( Nphoton +1) ; % Fock states
theta1 = 0.5* atan (2* g* sqrt (1) /D);
phi_1m = cos ( theta1 )* kron ( down , Fock (: ,2) )...
- sin ( theta1 )* kron (up , Fock (: ,1) ); % Initial state |1 , - >
PSI_0 = phi_1m ;
for k =1: L -12 PSI_0 = kron ( PSI_0 , phi_1m ); % Many body wavefunction |1 , - >...|1 , - > (L terms )
end
dn_T = zeros ( size ( t)); % Standard deviation dn_i = <n_i ^2 > - <n_i >^2
P1m = zeros ( size ( t)); % Population |1 , - > at time t
for n =1: length (t)
if n ==1
PSI = PSI_0 ; % Initial wavefunction
else
PSI = U* PSI ; % Wavefunction at time t_n
end
dn = 0;
for i =1: L
dn = dn + PSI'* N_ex {i }^2* PSI -( PSI'* N_ex {i }* PSI )^2;
end
P1m (n ) = abs ( PSI_0'* PSI ) ^2; % Ground state probability
dn_T (n) = dn ; % Standard deviation of the number of excitations
end
OP = mean ( dn_T ); % Order parameter
end
and
Nsim = 25; % Number of simulations
L = 2; % Number of cavities
wc = 1; % Cavity frequency
g = 1e-2* wc ; % Atom - light coupling
J = 1e-4* wc ; % Coupling between cavities
Nph = 2; % Number of photons per cavity
dimFock = Nph +1; % Dimension Fock space for photons
dimT = 2* dimFock ; % Dimension atom + cavity system
Deltai = 10^( -2) *g; % Initial detuning
Deltaf = 10^(+2) *g; % Final detuning
xi = log10 ( Deltai / g); % Initial detuning in log scale
xf = log10 ( Deltaf / g); % Final detuning in log scale
dx = (xf - xi ) /( Nsim -1) ; % Step dx
x = xi : dx : xf ; % Vector x to plot transition phase
OP_JC = zeros ( size (x) ); % Order parameter Jaynes - Cummings model
OP_R = zeros ( size ( x)); % Order parameter Rabi model
A = cell (1 , L); % Cell array to storage \hat{a}_i operators
Sp = cell (1 , L ); % Cell array to storage \ hat {\ sigma }_i ^+ operators
N_ex = cell (1 , L); % Cell array to storage N_i operators
Iatom = eye (2) ; % Identity matrix atom system
Icav = eye ( dimFock ); % Identity matrix cavity system
Is = eye (2* dimFock ); % Identity matrix atom + cavity system
function x =acav(i ,L , Nph ,Is , Iatom )
a = diag(sqrt(1:Nph)',1) ;
a = kron ( Iatom ,a);
Op_total = cell (1 , L) ;
for site = 1: L
Op_total { site } = Is + double ( eq (i , site ))*(a - Is );
end
x = Op_total {1};
for site = 2: L
x = kron (x , Op_total { site }) ;
end
end
function x = sigmap(i ,L , Is , Icav )
up = [1 0]';
down = [0 1]';
sigma_p = up * down';
sigma_p = kron ( sigma_p , Icav );
Op_total = cell (1 , L) ;
for site = 1: L
Op_total { site } = Is + double ( eq (i , site )) *( sigma_p - Is );
end
x = Op_total {1};
for site = 2: L
x = kron (x , Op_total { site }) ;
end
end
0 comentarios
Respuesta aceptada
Voss
el 18 de Abr. de 2022
Editada: Walter Roberson
el 19 de Abr. de 2022
If the intent is that the local functions defined in the scripts accc.m and comple.m (those local functions being acav, sigmap, and QuantumSimulationCavityArray) be accessible from the main script, then that can be achieved by having those two scripts (accc.m and comple.m) create function handles to the functions they contain.
However, it's probably easier to make those three local functions defined in those two scripts into functions in their own m-files, which can then be called from anywhere. I've done this, and the m-files are attached here (including main_script.m, which no longer calls accc.m and comple.m, since they are no longer needed).
main_script
2 comentarios
Walter Roberson
el 19 de Abr. de 2022
Create a new directory and put the scripts that _ posted in the directory, and run the code from that directory. You will get an error about matrix multiplication, not an error about acav not found.
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!