필터 지우기
필터 지우기

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

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

추가 답변 (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