Index a matrix multiplied by a time dependent function

조회 수: 3 (최근 30일)
guilherme stahlberg
guilherme stahlberg 2019년 7월 10일
댓글: Walter Roberson 2019년 7월 12일
Hi there,
I'm trying to index a matrix that's multiplied by a time dependent function, but keep getting the error "inner dimensions must agree" in the U expression line. I need to know the exact matrix values for each interaction related to the function E(t) in the time, i.e., U(1) related to E(1) and so on. Thanks in advance!
Here's the code
%% Quantum Control
format long
clear all
clc
%% Variables
fs=10;
ft = -20000:1/fs:20000; % Time
alpha = 0.001; % Time parameter
beta = 0.001; % Time parameter
ai = 0.2; % Pop |1>
ai2 = 0.8; % Pop |2>
af = 1; % Pop Final |1>
w0 = 0.02; % w0 = (E2 - E1)/h
mi = 6; % Dipole
phii = pi/24; % Relative phase
phif = pi/4; % Relative phase final
E1 = 1; % Energy
E2 = 2; % Energy 2
H = [0 1;1 0]; % Interaction hamiltonian
H0 = [E1 0;0 E2]; % Matriz do Hamiltoniano sem Interação
%% Control function
g = 1./(1+exp(-alpha.*ft));
f = ai*(1-g)+af*g;
p = 1./(1+exp(-beta.*ft));
h = phii*(1-p)+phif*p;
%% Electric field
E = alpha.*(af-ai).*exp(alpha.*ft).*sin(w0.*ft+h)./(mi.*(1+exp(alpha.*ft)).*sqrt((1-ai+(1-af).*exp(alpha.*ft)).*(ai+af.*exp(alpha.*ft))))+2.*beta.*(phif-phii).*exp(beta.*ft).*sqrt(f.*(1-f)).*cos(w0.*ft+h)/(mi.*(1-2.*f).*(1+exp(beta.*ft).^2));
%% Time evolution operator
[V, D]=eig(H);
Z = expm(H0);
Z1 = expm(D);
U = exp(-1i.*ft./2).*Z.*exp(1i.*mi.*E.*ft).*V.*Z1.*inv(V).*exp(-1i.*ft./2).*Z;
%% End
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 7월 10일
V.*Z1.*inv(V) is probably a mistake. Any multiplication of a matrix and its inverse should be using * instead of .*
You should likely also be coding using Z1/V instead of Z1.*inv(V)
In your long expression you have a / that should probably be ./
guilherme stahlberg
guilherme stahlberg 2019년 7월 10일
I've tried either * or .* but keep getting the same error "inner dimensions must agree". Same regarding the / and./

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2019년 7월 10일
U = zeros(2,2,length(ft)) ;
for i = 1:length(ft)
U(:,:,i) = exp(-1i.*ft(i)./2).*Z.*exp(1i.*mi.*E(i).*ft(i)).*V.*Z1.*inv(V).*exp(-1i.*ft(i)./2).*Z;
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 7월 12일
This is likely to be mathematical nonsense though. V.*Z1.*inv(V) is much more likely to need V*Z1*inv(V) or similar.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Quantum Mechanics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by