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

2 ビュー (過去 30 日間)
Blaz Serna
Blaz Serna 2016 年 11 月 17 日
コメント済み: Blaz Serna 2016 年 11 月 17 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by