フィルターのクリア

ode45 gets stuck when making the function a column vector?

2 ビュー (過去 30 日間)
Physics
Physics 2016 年 12 月 17 日
コメント済み: Star Strider 2017 年 3 月 3 日
I am trying to solve a relatively simple ode. I am aware I could possibly use a different ode function but don't think that is the problem.
I get the very common error that my function must return a column vector, so then add the dx=zeros(2,1) line into my function.
When I do this however the programme doesn't complete - it starts but then seems to get stuck somehow, busy.
If I instead transpose my dx to get a column vector, the result is the same.
This is my function:
function dx = minibandvel(t,x)
F=1^(-20);
tau=10^(-5);%s
del=19.1*10^(-3);%eV
d=8.241*10^(-9);%m
hbar=10.5*10^(-34);
%dx=zeros(2,1);
dx(1)=((tau*del)/(2*hbar))*sin(x(2));
dx(2)=(F*d*tau)/hbar;
%dx=dx.';
end
used in this:
close all
clc
initialx(1)=0;
initialx(2)=0;
tspan=[0 0.1];
[t,x]= ode45 (@minibandvel,tspan,[initialx(1) initialx(2)]);
plot (t,x)
The odd thing is that I had run the programme several times successfully; and had this issue before but it could be solved by simply restarting MATLAB.
Thanks in advance

採用された回答

Star Strider
Star Strider 2016 年 12 月 17 日
Looking at your constants:
tau=10^(-5);%s
del=19.1*10^(-3);%eV
d=8.241*10^(-9);%m
hbar=10.5*10^(-34);
The ode45 solver will get there, but it could take several hours. A better — and certainly faster — solution is a ‘stiff’ solver such as ode15s.
  2 件のコメント
Physics
Physics 2017 年 3 月 3 日
Thanks for your reply.
The solution I found was to define the fraction used and then input that into the ODEs.
For example, fraction=(F*d*tau)/hbar;
and then
dx(2)=fraction
Star Strider
Star Strider 2017 年 3 月 3 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by