Reputation: 2801
Suppose we have this Hamiltonian:
n = 10;
H = ones(n,n);
The density matrix is:
Ro = sym('r',[n,n]);%Density matrix
The equation of motion is:
H*Ro-Ro*H
The above equation of motion is the right hand side of the equation, the left hand side is the time derivative of density matrix.
How can I solve the equation of motion in Matlab without the symbolic math toolbox? I need to change the value of n. It can be up to 100.
Upvotes: 1
Views: 185
Reputation: 1222
In your dynamics function, reshape between vectors and matrices in order to use MATLAB's standard ode
functions, which (to my knowledge) require vector inputs. Note, the symbolic toolbox isn't used anywhere in this solution. R
can be any size n-by-n
, within the constraints of your machine's memory.
function dR = dynfun(R,H)
%// R = n^2-by-1 vector
%// H = n-by-n matrix
n = sqrt(length(R));
R = reshape(R,[n,n]); %// reshape R to n-by-n matrix
dR = H*R-R*H;
dR = dR(:); %// reshape dR to n^2-by-1 vector
end
Call the ODE solver:
[tout,Rout] = ode45(@(t,R) dynfun(R,H), [0,T], R0(:));
where T
is final time, R0
is n-by-n
initial condition, tout
are the output time steps, and Rout
is the solution trajectory. Note due to the reshaping, Rout
will be k-by-n^2
, where k
is the number of time steps. You'll need to reshape each row of Rout
if you want to have the actual matrices over time.
Upvotes: 0