ode45 gets stuck when making the function a column vector?

2 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by