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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!