Error using ode arguments (line 90) SCHROE must return a column vector?

조회 수: 4 (최근 30일)
This is to simulate a nth Eigenstate of a initial hamiltonian being carried under the Schrodinger equation to the nth eigenstate of the final hamiltonian.
Script:
function [dy]= schroe(t, y);
global lambda Delta
H0 = [ lambda*t, Delta
Delta, -lambda*t];
dy=-1i*H0*y;
Command Window:
lambda=1;
Delta=1;
Hz=20;
tt = [0/lambda:Hz/lambda/200:Hz/lambda];
y0 = [.999688036058711-.024976600270607];
options = odeset('Reltol', 1e-6, 'AbsTol', 1e-6);
[ttotal, ytotal] = ode45(@schroe, tt, y0, options);
for ii= 1:201;
ti=tt(ii);
H0 = [ lambda*ti, Delta
Delta, -lambda*ti];
[vt, et] = eig(H0);
psit=transpose(ytotal(ii,:));
vg=vt(:,1);
ve=vt(:,2);
cg(ii)=vg'*psit;
ce(ii)=ve'*psit;
end;
Error:
Error using odearguments (line 90)
SCHROE must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in lz_2level_simu_lt (line 27)
[ttotal, ytotal] = ode45(@schroe, tt, y0, options);
Please Help

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 17일
Your y0 is
y0 = [.999688036058711-.024976600270607];
which is a numeric scalar. Your schroe function is therefore going to receive numeric scalars for y, and will construct -1i*H0*y where H0 is a 2 x 2 matrix. That is going to give a 2 x 2 result, and that is going to fail the consistency tests. It also fails the consistency tests about the number of returned elements being the same as the number of inputs, since you are returning 4 outputs for 1 input.
If your y0 were instead
y0 = [.999688036058711 -.024976600270607];
which would be a vector of length 2, then the ode45 would create a column vector from the size, and so would be passing in 2 x 1 for y. Your -1i*H0*y would then be doing matrix multiplication, (2 x 2) * (2 * 1) which would give a 2 x 1 result, which would be fine.
  댓글 수: 1
Blaz Serna
Blaz Serna 2016년 11월 17일
Wow, thank you so much Walter. I definitely need to be aware of that.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by